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!

VBA can't find my form.

Status
Not open for further replies.

mpmoore

Technical User
Apr 5, 2001
27
0
0
US
If [Forms]![Dealer]![Checkbox] Then
Me!BranchID = "R-3701"
Else
Me!BranchID = "R-3700"
End If


Upon entering the above code I get the following error.
Microsoft Access can’t find the form ‘Dealer’…

I have checked the spelling and the location. I haven’t received this error on any other code that I have written.
 
Your code is not supplying an calculation to be evaluated by your if function, it should be something like this:

If [x] = [y] Then
Me!BranchID = "R-3701"
Else
Me!BranchID = "R-3700"
End If


Are trying to say:

If this is the dealer form, then BranchID = "R-3701" otherwise it's "R-3700"

If so then the code needs to be changed. Please provide what you are trying to do. Joe Miller
joe.miller@flotech.net
 
Actually, it looks like he is trying to say if this check box on the dealer form equates to true, set the BranchID = "R-3701". Checkboxes = -1 when checked and 0 when unchecked, so try this:

If [Forms]![Dealer]![Checkbox] = -1 Then
Me!BranchID = "R-3701"
Else
Me!BranchID = "R-3700"
End If


Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
Shouldn't the syntax be:

If Forms!Dealer.Checkbox Then

1. The separator between Dealer and Checkbox should be a period not an exclamation.

2. You don't need to explicity test for a true value.

Hope that helps.
Larry De Laruelle
larry1de@yahoo.com

 
Terry,

After reading it again, I'm sure that you are right... ah well can't get em all I guess!

<swearing at self under breath> ;-) Joe Miller
joe.miller@flotech.net
 
You are right Joe, Larry just proved I didn't look to close either. Oh well, as long as mpmoore gets the correct answer soon... Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
Hey,
I appreciate all of the assistance. However, I still don't have a solution. After trying all of the methods described in the above posts, I still get the error. It is Run Time Error 2450 - Microsoft Access can't find the form 'Dealer' referred to in a macro expression or visual basic code. Again, I have checked and rechecked the spelling.
Thanks for any tips.
Michael

 
It appears that you are running the code somewhere other than the dealer form and the dealer form is not open when you run the code. I simulated this situation and got your 2450 error. So if you are trying to look up a value on Dealer from another form then Dealer must be open at the time you execute the code. The examples we gave were for when you are on the dealer form and need to modify data on based on the value of another control on form dealer. Are we getting closer??
Joe Miller
joe.miller@flotech.net
 
That was it! The &quot;Dealer&quot; form wasn't open. Is there any way to do this without the other form being open? Possibly basing the code on the table the &quot;Dealer&quot; form is bound to? Seeing as though this is a data entry form, I really don't want to have other forms open. I guess I could set it up to open invisible, couldn't I?

You have been a tremendous help. Thank you very much. I had exhausted all the people I knew and was very frustrated combing my assorted Access and VBA books.

Michael
 
There really isn't a way to do it without the form being open. The underlying reason for this is that Ms. Access would not know which record you could possibly be on without the form being open and pointing to a recordset.

Open and hidden sounds like the way to go. Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
You could use a dlookup function to see what the value of the field is in the table. Use help and look it up, the explanation should get you going.

Joe Miller
joe.miller@flotech.net
 
Will try both ideas. Thanks for the tips. (-:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top