variable not defined error

crich21

Registered User.
Local time
Today, 09:55
Joined
Jan 10, 2003
Messages
97
Could anyone maybe explain why I would be getting this error. I have been using this db and made a couple of changes and now I get this error when I try to compile it.

Private Sub addtocustomer_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim strSQL As String

strSQL = "INSERT INTO tblOrders (ProductID, CustomerID)" & _
" VALUES(" & Chr(34) & ProductID & Chr(34) & ", " & Chr(34) & CustomerID & Chr(34) & ")"

CurrentDb.Execute (strSQL)
DoCmd.Close

End Sub
 
crich21

Are you sure you didn't also change the name of the "CustomerID" control?

Chris
 
it's not so bad to allways use the Me prefix to reference a control inside the forms class module. Your code might fail if you'll open the form more than once. i.e. Me.CustomerID

To your question - click on the control, which you use for the CustomerID and check in the property editor under the register other if the control has the expected name. You can just rename it to CustomerID.
 
i am really sorry

Thank you ChrisO for pointing out the obvious. I guess now would be a good time to take a break.

Yes I did change the form I was rearranging the form and must have accidentally erased the textbox. Thank you Nouba for the information I will take all the advice I can get. After all, learning vba doesn't happen overnight.
 

Users who are viewing this thread

Back
Top Bottom