View Full Version : Strange "Variable not defined" error


ovello
08-08-2005, 12:22 AM
Hello,

I made a form with a field and I set a GotFocus function for it:

Private Sub NRCDA_GotFocus()

Dim SQL As String

' i build the qry
SQL = "SELECT * FROM NRCRT"

' recordset variable
Dim r As Recordset

' open the recordset
Set r = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)

End Sub

If I don`t write the line Dim SQL As String I get the error "Variabile not defined". What is strange here is that, in another application, the same function works. In the code above another error occured "Compile error: Variabile not defined", and the error referes to the last line of the code:

Set r = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)

and says that the variable dbOpenSnapshot is not defined. What`s wrong? Why I get these errors? How can I avoid them? I repeat that the same code works in another application.

Thank you in advance!

Rich
08-08-2005, 01:22 AM
It sounds as though you have a missing/broken reference, use the search function here for solutions, or it might be this (http://www.access-programmers.co.uk/forums/showthread.php?t=61060)

RuralGuy
08-08-2005, 12:26 PM
It sounds to me like you *finally* have Option Explicit at the top of the code page. :)