RE: Compile Error: Variable Not Defined

Tech-Archive recommends: Fix windows errors by optimizing your registry



Take out Option Explicit and see if it runs without it. I use it but maybe
you have a variable that is not declared and it is not showing. Usually it
highlights the variable that is not defined.


"Tara" wrote:

FGM, I just checked, and require variable declaration is not on, and the
General Declarations do require Option Explicit.

I'd appreciate any other help you can give.

"FGM" wrote:

Under the VBA window check Tools then Editor tab and see if require variable
declaration is on.

Also, on the VBA input window General Declaration see if it requires Option
Explicit.
Option Compare Database
Option Explicit




"Tara" wrote:

All of our databases have Login forms. I've reused these forms and the
associated tables many times in the past with other databases (the original
Login form was part of a database that already existed before I started
working here). Now, for the first time, I'm having a problem with it.
Obviously, the code indicates that the variable isn't defined, so I defined
it. Unfortunately, it then just goes on to the next Case statement, and
breaks there. In looking at our other databases, I realized that the
variables aren't defined in those either, at least not that I can see, and
they work perfectly. I'm not proficient at all with coding, and I'm lost
trying to figure out what the underlying issue is. Here's the code
involved...the code originally broke at Case ltNone. Any help is greatly
appreciated!

Private Sub Form_Load()
Dim rst As New ADODB.Recordset
Dim strUser As String

On Error GoTo ErrHandler
rst.Open "SysMisc", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
bUsePasswords = rst.Fields("UsePasswords")

Select Case rst.Fields("Login")
Case ltNone
cmdEnter_Click

Case ltWindows
strUser = GetUser
rst.Close
rst.Open "SELECT * FROM sysEmployees WHERE
sysEmployees.WindowsLogin='" & strUser & "'", CurrentProject.Connection,
adOpenStatic, adLockReadOnly
If rst.RecordCount > 0 Then
Me.comEmployeeID = rst.Fields("EmployeeID")
If bUsePasswords = False Then
cmdEnter_Click
Else
Me.txtPassword.Visible = bUsePasswords
End If
Else
Err.Raise 550, "sysLogin.Form_Load", "Unauthorized access
attempted: " & strUser
rst.Close
Set rst = Nothing
DoCmd.Quit
End If
Case ltDatabase
Me.txtPassword.Visible = bUsePasswords
End Select
rst.Close

ExitHere:
Set rst = Nothing
Exit Sub
ErrHandler:
If Err.Number = 550 Then
MsgBox Err.Description
Application.Quit
Else
MsgBox Err.Description
End If
Resume ExitHere
End Sub
.



Relevant Pages

  • Re: Syntax to connect to A2K DB with a DB password using VBA
    ... You stated that your code below works for a database without a password, ... there are a few lines of code missing from the code snippet you posted ... Tom Wickerath's explanation of why you should _always_ use "Option Explicit" ... I'd also like to point out that your declaration of "strDBName" (which, ...
    (microsoft.public.access.externaldata)
  • RE: Compile Error: Variable Not Defined
    ... General Declarations do require Option Explicit. ... Login form was part of a database that already existed before I started ... If bUsePasswords = False Then ...
    (microsoft.public.access.modulesdaovba)
  • Re: Performance concerns in SPs and Tables
    ... would expect memory to be allocated on declaration; for a varchar, ... procedural code; database access code should be declarative. ...
    (microsoft.public.sqlserver.programming)
  • RE: Compile Error: Variable Not Defined
    ... If Option Explicit was already there and you removed it, ... click Login, I now get a new Compile error. ... loginSuccessful = True of the following code. ... declaration is on. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Option Explicit not working
    ... Option Explicit must be present in ALL modules where you want variables to ... > a simple Dim of a string.. ... > In options the "Require Variable Declaration" is set. ... > hey presto the compiler finds the undeclared variable.... ...
    (microsoft.public.access.modulesdaovba)