Now I've gone and Done it HELP!!! Compile Error:

SheaLee

Registered User.
Local time
Yesterday, 18:51
Joined
Dec 22, 2005
Messages
40
Compile Error: Variable not defined
yesterday I went out to the MS site to install the coding to disable the wheel function on the mouse. After padding myself on the back, cus it worked, I called it a day and went home. Today I came in to run a report and to my suprise I'm getting the compile error. Can anyone help me figure out where I went so wrong?? I did do a Ctl G and selected the MS DAO 3.6 Object Library but this didn't fix it, as you now can tell I'm a newbie.
 
did you put in
option explicit
If so then you will have to declare all your variables, or remove it. I do not know of anything else that would cause that error, off the top of my head
 
Yes When I installed the new code I added option explicit

What is the danger of removing option explicit??
 
D'oh Danger Danger boys and girls

I just found out what happens when removing the option explicit. It's not pretty. Hoping someone will take a look at what I have currenlty and help me fix it to work in my new world called OPTION EXPLICIT!!

I have a button on a form that generates reports based on a search.

Private Sub cmdINW_Click()
If Me.SearchBy = "Bay" Then
Dim stDocName As String
stDocName = "rptIWUBayItem"
stLinkCriteria = "[NoID]=" & Me![txtNoID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
ElseIf Me.SearchBy = "PCI" Then
stDocName = "rptIWUPCIItem"
stLinkCriteria = "[NoID]=" & Me![txtNoID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
Etc.....
End if
End Sub
 
I would suggest to just find the variable that is not declared, and declare it. But you can usually remove the option explicit without any problem. Any variable not declared will be assumed to be a variant type. this is normally not a problem, unless you try to do this with large arrays, then you can start to run short on memory. but if your program is relativly small, then you should be able to remove the option explicit with no problems. unless stLinkCriteria is declared elsewhere, or is global, then declaring that should help, if there are no others.
 
when I tried to delete the option explicit the data base shut down
the system is asking me to declare
"Dim stDocName as String ="
I'm really new how do I do this??
 
I think you just have the DIM out of order:

Change it like this, because in the code you posted, you are declaring the variable in your code ONLY if it meets the first IF statement and the variable is used outside of that IF statement so you do not want to put it in that IF statement, but outside of it.

Code:
Dim stDocName As String
If Me.SearchBy = "Bay" Then
stDocName = "rptIWUBayItem"
stLinkCriteria = "[NoID]=" & Me![txtNoID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
ElseIf Me.SearchBy = "PCI" Then
stDocName = "rptIWUPCIItem"
stLinkCriteria = "[NoID]=" & Me![txtNoID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
Etc.....
End if
 
Hmmmm

I'm still getting the and it is showing up on this line
stLinkCriteria = "[NoID]=" & Me![txtNoID]
please don't give up me
 
Can you post the lind where you are declaring stLinkCriteria? If you are not declareing it, you can try putting

dim stLinkCriteria as string

right under

Dim stDocName As String

or you could even use somthing like

Dim stDocName, stLinkCriteria as string
 
I Can not thank you enough

My phone has been ringing off the hook to get this fix, I was so nervous I forgot to add the statement dim stLinkCriteria as string
Thanks again, Don't know what I'd do without this site....perhaps get a job at Walmart like every other american...
 
Just a dumb question. When you get the compile error due to an undeclared variable, doesn't it highlight the variable in question?
 

Users who are viewing this thread

Back
Top Bottom