Compile Error: Variable Not Define

darreno

Registered User.
Local time
Today, 10:52
Joined
Jun 16, 2007
Messages
54
I encountered a Compile Error: Variable not Define on the following combobox and have no idea how to fix it.

Private Sub cboFYE_AfterUpdate()
On Error Resume Next
cboBeginDate.RowSource = "Select tblBeginDate.BeginDate " & _
"FROM tblBeginDate " & _
"WHERE tblBeginDate.FYE = '" & cboFYE.Value & "' " & _
"ORDER BY tblBeginDate.BeginDate;"
End Sub


Thanks for any advise.:D
 
Try:
Private Sub cboFYE_AfterUpdate()
On Error Resume Next
cboBeginDate.RowSource = "Select tblBeginDate.BeginDate " & _
"FROM tblBeginDate " & _
"WHERE tblBeginDate.FYE = '" & Me.cboFYE.Value & "' " & _
"ORDER BY tblBeginDate.BeginDate;"
End Sub
 
I am still having the error message. BTW, I have these lines at the beginning:

Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox

The error started after I added the last 2 lines for a calendar.
 
Option Explicit forces you to define your variables before you use them. It is not a good idea to eliminate errors with On Error Resume Next. Do Debug>Compile and see what line the compiler is updet with.
 
After Debug>Compile, the error is on "cboBeginDate".
 
I always use the me. predicate when refering to controls. Did you misspell the name of the control? Me.cboBeginDate
 
I always use the me. predicate when refering to controls. Did you misspell the name of the control? Me.cboBeginDate
Allan:
If you notice, in the post that you suggested he use the ME. keyword, you didn't suggest it on cboBeginDate in the first spot. You suggested it on the cboFYE.Value part. I think he may need to just add that to all of the controls, although I've seen it work before without the Me. part added. But, if the control name and field name are the same that may confuse Access and the Me. may be necessary then.
 
You are probably right Bob. Is it me or is your signature growing?? :confused::p
 
You are probably right Bob. Is it me or is your signature growing?? :confused::p

I just replaced one graphic with another :D is it getting too long? :rolleyes: If so, I guess I can shorten it up a bit. At least it doesn't store it but just displays the most current. :)
 
Rural: I deleted Option Explicit and it is working now. Guess that is not required?
 
Rural: I deleted Option Explicit and it is working now. Guess that is not required?

That is a BAD idea. Option Explicit is something that helps you make sure that any variables you use have been declared. It keeps you from wanting to use something like strSQL but you mistype and use strSCL in your code, it won't squawk if you don't have option explicit in there. It will just assume that you know what you are doing and use strSCL which will then either not match up with what you are really wanting, or it may work and it will just use it as a variant but you will not know for sure what is what.
 
Rural: I deleted Option Explicit and it is working now. Guess that is not required?
I completely concur with Bob. I strongly suggest you leave Option Explicit in your Class module and figure out why it is causing you problems. Something is probably misspelled and the code is not working the way you think it is.
 

Users who are viewing this thread

Back
Top Bottom