Database FE freezes up every time I try to open it. (1 Viewer)

krc547

Member
Local time
Today, 17:48
Joined
Sep 1, 2023
Messages
38
I have a database that I am working on just changing some design stuff from the one I have now. The old one runs fine and the new one ran fine until I copied this code over which is identical to the old one and all the tables are the same but the FE freezes every time I try to open it.
Code:
Private Sub cmdLogIn_Click()
If userName & password = Null Then
  Exit Sub
 
 ElseIf Not password = DLookup("password", "tlogin", "userID = " & txtID) Then
        message = "Wrong password or Username Please write the correct info..!"
          Exit Sub
ElseIf password = DLookup("password", "tlogin", "userID = " & txtID) Then
        If IsNull(DLookup("startup", "tstartupForm", "startupID =1")) Then
            DoCmd.Close
            DoCmd.OpenForm "fsettings_plugin"
        Else
            DoCmd.SetWarnings False
            DoCmd.RunSQL ("UPDATE tTemp Set userID =" & Me.txtID)
            DoCmd.Close
            Dim srt As String
            srt = DLookup("startup", "tstartupForm", "startupID =1")
            DoCmd.OpenForm (srt)
        End If

 End If
End Sub

Private Sub userName_AfterUpdate()
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("Select * from tlogin where userID =" & userName)
   If rst!remember = True Then
        txtID = rst!userID
        Me.password = rst!password
        message = ""
    Else
        txtID = rst!userID
        message = ""
        Me.password = ""
    End If
End Sub
 
did you put a stop point at the 1st line, then step thru the code (F8) to see where the stall is?
prob at the: Set rst =.

sometimes is a REFERENCE that wont quite work.
vbe (alt-F11) , tools, references.
are there any checked, but say MISSING?
 
I tried, but it just kept freezing up.
 
IS there code that runs at startup?
hold SHIFT KEY ,then open the db.
 
I did that, that is how I was able to get back in and copy the code. But when I try to step into it, it just freezes or stops working.
 
What version of Access was your old (working) version of the db created in?

What version of Access is your new (non-working) version of the db created in?

Do you have Option Explicit declared at the top of *every* code module (above or below Option Compare Database)?

You have code which will probably cause errors in modern versions of Access:
Code:
Private Sub userName_AfterUpdate()
Dim db As Database      ' <-- Unqualified reference, should be: Dim db As DAO.Recordset
Dim rst As Recordset    ' <-- Same, should be: Dim rst As DAO.Recordset
' ...

Also, this code:
Code:
Private Sub cmdLogIn_Click()
If userName & password = Null Then
  Exit Sub
Where are userName and password declared? Are they controls on the form, or perhaps fields in the form's Recordset? Or are they just variables?
 
So it looks like the error in my code is in this spot:

Private Sub cmdLogIn_Click()
If userName & password = Null Then
Exit Sub

ElseIf Not password = DLookup("password", "tlogin", "userID = " & txtID) Then


It works on the original, but not the new one that I am working with.
 
What version of Access was your old (working) version of the db created in?

What version of Access is your new (non-working) version of the db created in?

Do you have Option Explicit declared at the top of *every* code module (above or below Option Compare Database)?
 
I am using Microsoft 365, the new version was edited and sent back to me, not sure his version. Option Explicit is declared at the top of each.
 
What happens if you go to the 'Debug' menu in the VBA editor and click 'Compile'?

Does it raise any errors?
 
So check you have a textbox on your form called txtID.

If not, is it supposed to be a variable?

If there is definitely a textbox on your form called txtID and you have double-checked the spelling, then you should follow Colin's instructions to decompile/compact and repair.
 
I don't have a box named txtID on the new or old and the old works just fine. So weird. I think in the second part of the code that I posted that txtID=userID.
 
On the old version, is there a module level variable declared somewhere called txtID?
 
In the old version that works OK, right-click on the txtID in the VBA editor and choose 'Definition'.

It should take you to where the variable is declared.
 
This is what it says when I click on it and go to definition:

1698861605711.png
 

Users who are viewing this thread

Back
Top Bottom