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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement not working? 1

Status
Not open for further replies.

osx99

Technical User
Apr 9, 2003
250
0
0
GB
I am new to VB code and am trying to do the following code in access 2000 but doesn't work? Can anyone help

Private Sub Site_Works___Labour_AfterUpdate()

If (Forms![Structure Data Input]![GRIP Stage] = 7) Then
Forms![Structure Data Input].[Costs Subform]![GRIP Stage 7 Total] = Forms![Structure Data Input].[Costs Subform]![Site Works - Labour]
End If

End Sub

'Site Works_ Labour' is a control in a subform [Costs Subform] of parent form [Structure Data Input]

Essentially I want to test the field GRIP Stage 7 on the parent form and perform a calculation on the subform components only based upon the result.

Many thanks,
Osx
 
Hi!

You need to do it like this:

If (Forms![Structure Data Input]![GRIP Stage] = 7) Then
Forms![Structure Data Input].[Costs Subform].Form![GRIP Stage 7 Total] = Forms![Structure Data Input].[Costs Subform].Form![Site Works_Labour]
End If

That tells Access to treat the subform like a form instead of a control

hth


Jeff Bridgham
bridgham@purdue.edu
 
osx99

There is a little reference problem in the way you wrote the code to reference your controls and value boxes.

On the parent form the subform box which is the element that has to be referenced has to have a direct name. Irregardless of what form is actually in it. Lets say for this purpose that the name in "MySubForm"

Then you can use the following line to look up the value as in your problem.

forms![Structure Data Input].MySubForm![GRIP Stage 7 Total].value

And then you can assign it as you need to.


Hope this helps

Urbane Rove
 
Did it worked, dude ?
If not here my thingie

[Forms]! should be in parentesies
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top