Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the Value of a Form Object

Status
Not open for further replies.

mbudash

MIS
Sep 14, 2001
2
US
I am an ASP programmer who has to make a couple of changes to an Access 2k DB that was built by someone else. I have an Access form that has a text field that needs to be automatically calculated based on the value of two other form objects. I wrote the following function, which does not work all of the time:

'Calculate the amount of the 3 checks to be cut
Private Sub NumTrip_Change()
'NumTrip will be either 1 or 2. It is a form object name
If [NumTrip] = 1 Then
'CheckCat1,2,3 are form object names
'Category 1 is a form object name
Checkcat1 = ([Category 1] * 1.12) - 500
CheckCat2 = ([Category 1] * 1.08) - 500
CheckCat3 = ([Category 1] * 1.05) - 500
ElseIf [NumTrip] = 2 Then
Checkcat1 = ([Category 1] * 1.12) - 1000
CheckCat2 = ([Category 1] * 1.08) - 1000
CheckCat3 = ([Category 1] * 1.05) - 1000
ElseIf [NumTrip] = 0 Then
Checkcat1 = 0
End If
End Sub

Any help would be greatly appreciated.

MB
 
'Calculate the amount of the 3 checks to be cut
Private Sub NumTrip_After_Update()
'NumTrip will be either 1 or 2. It is a form field name
If me.NumTrip = 1 Then
'CheckCat1,2,3 are form field names
'Category 1 is a form field name
me.Checkcat1 = (me.Category1 * 1.12) - 500
me.CheckCat2 = (me.Category1 * 1.08) - 500
me.CheckCat3 = (me.Category1 * 1.05) - 500
ElseIf me.NumTrip = 2 Then
me.Checkcat1 = (me.Category1 * 1.12) - 1000
me.CheckCat2 = (me.Category1 * 1.08) - 1000
me.CheckCat3 = (me.Category1 * 1.05) - 1000
ElseIf me.NumTrip = 0 Then
me.Checkcat1 = ""
End If
End Sub

Note the changes place the code in the afterupdate not change.
Also me refers to current form and field.

hope this helps

Zero Anarchy
 
one other point make sure the field and table values are set to fixed, a good reason why it may not work even though the code is correct is that the format of the fields are set to text not numbers.

Zero Anarchy
 
Thanks. It sort of works - I can live with it. The fields are currency and numeric, so that was not the problem.

Thanks for the help.

MB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top