PDA

View Full Version : Command buttons keep displaying compile error when the code is ok



wedd
12-19-2011, 09:43 AM
Hi experts,

I have a command button that on the click event it should populate a blank combo box...compile error not defined. The code is fine but every time I either click on a button or run a compile I receive that message which is getting a bit frustrating. Any reasons why this keeps happening even though the code is fine? Is there a way I can resolve this error with code to erase this bug from occuring I am very soon to completing this project but this error keeps occuring...thanks for your contributions it's a great help to my understanding and resolving these issues:friends:


Private Sub PopulateButton1_Click() error is highlited in yellow
ComboBoxLocation.Items.Add ("Gym")
ComboBoxLocation.Items.Add ("Main Hall 2")
ComboBoxLocation.Items.Add ("Kitchen")
ComboBoxLocation.Items.Add ("IT Drop-In")
ComboBoxLocation.Items.Add ("Multimedia Suite")
ComboBoxLocation.Items.Add ("Nursery")
ComboBoxLocation.Items.Add ("Sports Hall")
ComboBoxLocation.Items.Add ("Classroom")
ComboBoxLocation.Items.Add ("Meeting Hall")
ComboBoxLocation.Items.Add ("Side Room")
End Sub

Aflatoon
12-19-2011, 10:19 AM
On what basis do you say the code is fine, when it gives you an error every time you run it?

wedd
12-19-2011, 10:24 AM
No, syntax is fine when I ran it on a different database...but for some reason unbeknown to me when I run it on my database the error message appears...:dunno i.e compile error: not defined. I had changed field names with new names using an an update query but the code doesn't seem to recognise the new names I replaced over the old names...

Aflatoon
12-19-2011, 10:44 AM
Your code refers to controls, not fields, so I suspect they are wrong. Also, should it not be AddItem rather than Items.Add?

wedd
12-23-2011, 05:21 AM
Ok. Thanks!