The right place to put my code

S

Stapes

Hi

I have a couple of calculated controls on a subform. I put the
calculations for them in the On Current event of the subform: -

Dim MyJobTime As Variant
MyJobTime = Calculate_JobTime / 2
Debug.Print MyJobTime
[Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![NUM_JobTime] = MyJobTime
[Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![CUR_Labour] = _
MyJobTime * [Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![Labour_Rate]
Dim MyPartsTotal As Variant
MyPartsTotal = Calculate_PartsTotal
[Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![Total_Parts] = MyPartsTotal


Trouble is, where no records exist, it calculates these controls &
places the values in the appropriate fields, thereby creating a new &
unwanted record.
Is there anywhere I can put this code where it will execute only when
a record exists?

Stapes
 
B

Bruno Campanini

Stapes said:
Hi

I have a couple of calculated controls on a subform. I put the
calculations for them in the On Current event of the subform: -

Dim MyJobTime As Variant
MyJobTime = Calculate_JobTime / 2
Debug.Print MyJobTime
[Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![NUM_JobTime] = MyJobTime
[Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![CUR_Labour] = _
MyJobTime * [Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![Labour_Rate]
Dim MyPartsTotal As Variant
MyPartsTotal = Calculate_PartsTotal
[Forms]![FM_MainDetails]![FMS_Boat_subform]!
[TM_JobDetails_subform].Form![Total_Parts] = MyPartsTotal


Trouble is, where no records exist, it calculates these controls &
places the values in the appropriate fields, thereby creating a new &
unwanted record.
Is there anywhere I can put this code where it will execute only when
a record exists?

OnCurrent:

If Recordset.RecordCount Then
<... Your Code ...>
End if

Bruno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top