Strange "Variable not defined" error

ovello

Registered User.
Local time
Today, 23:15
Joined
Jul 14, 2005
Messages
17
Hello,

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

Code:
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!
 
Last edited:
It sounds as though you have a missing/broken reference, use the search function here for solutions, or it might be this
 
It sounds to me like you *finally* have Option Explicit at the top of the code page. :)
 

Users who are viewing this thread

Back
Top Bottom