Help with code

AnnPhil

Registered User.
Local time
Today, 01:01
Joined
Dec 18, 2001
Messages
246
I have a main form with a subform. In the subform I want to add the number 1 to a field if the data in another field = "Primary" I wrote the following in the After Update event of the first field but it doesn't seem to work. Any help would be appreicated. Thanks

Private Sub AssocType_AfterUpdate()

If Me.[ContractAssociates subform]![AssocType] = "Primary" Then
Me.[ContractAssociates subform]![PctPmt] = 1
End If

End Sub

What am i missing here?
 
Its the way you're referencing the sub form.

If Forms!MainForm!Subform.Form!FieldName = "Primary" then
Forms!MainForm!Subform.Form!FieldName = 1
End if

Replace with your names where appropriate

HTH
John
 
Thanks John, i tried that also and got the same error message, i dont have a clue as to what is wrong. Any other suggestion?
Here is the error message i get:

The expression After Update you entered as the event property setting produced the following error: A problem occurred while Microsoft Access was communicating with the OLE server or Active X control.
*The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

Thanks for your help
 
You cannot set the value of a subform control using the Me. keyword from the main form, you have to set focus to the subform and then set focus to the control, then setthe value.
 
Thanks Rich,

Tried that, still didnot work. The subform is in a tab control, so i also tried set focus on that before the subform and still get same error. I have the code in the after update of the first field in the subform so doesn't the field already have the focus?

Confused
:(
 
If a field in your subform already has the focus, you don't need to include the reference to your subform. Just use Me![Assoc Type] etc in your expression
 

Users who are viewing this thread

Back
Top Bottom