If True Go to Control

Hey Lucy

Registered User.
Local time
Today, 11:58
Joined
Jan 20, 2012
Messages
124
I'm trying to create a simple embedded macro for a checkbox control on a form [Company?]. The default value for this checkbox is No. I want to write an If statement that basically says "If[Company?] = Yes, then GotoControl[CompanyorNameCombo], Else GotoControl[CustomerFN]

Although the checkbox field label and the control itself IS named [Company?] in the table and set as a Yes/No field, when I try to write the If statement I get an error that says "Microsoft Access cannot find the name 'Company?' you entered in the expression"

I can't figure out why not. That's the name of the control and it is included in the table and shows in the field list. Any ideas?
 
I'm assuming you actually want VBA code and not a macro. If you want a macro, you can get help in the macro forum.
In the AfterUpdate event of the checkbox control:
Code:
If Me.[Company?] = True Then
    Me.CompanyOrNameCombo.SetFocus
Else
    Me.CustomerFN.SetFocus
End If

PS - Names should not include embedded spaces or special characters and they shouldn't duplicate the names of any functions or properties for VBA or SQL.
 
Thanks for your response and the code. I don't know VB but am learning a little about inserting code that someone has already written.

Here's a weird thing -- even though I get the error message when I write the If statement as an embedded macro, when you actually use the form it works and there are no errors. Haaaa.

Thanks again.
 

Users who are viewing this thread

Back
Top Bottom