The OpenForm action was canceled (1 Viewer)

vent

Registered User.
Local time
Today, 10:37
Joined
May 5, 2017
Messages
160
Hi everyone

So i'm working on creating a classic login form. The VBA I wrote did initially work but now suddenly I get this error The OpenForm action was canceled I don't know what happened but if someone could have a look at my VBA and maybe offer some guidance, that would be appreciated. Thank you!



Private Sub btnLogin_Click()

Dim RecSet As Recordset

Set RecSet = CurrentDb.OpenRecordset("tblEmployees", dbOpenSnapshot, dbReadOnly)

RecSet.FindFirst "userName='" & Me.txtUserName & "'"

If RecSet.NoMatch = True Then
Me.lblInvalidUserName.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblInvalidUserName.Visible = False


If RecSet!Password <> Nz(Me.txtPassWord, """") Then
Me.lblInvalidPassword.Visible = True
Me.txtPassWord.SetFocus
Exit Sub
End If
Me.lblInvalidPassword.Visible = False
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, Me.Name

End Sub


DoCmd.OpenForm "frmMain"is highlighted yellow and seems to be the problem but I'm confused because it was working previously
 
Last edited:

Ranman256

Well-known member
Local time
Today, 10:37
Joined
Apr 9, 2015
Messages
4,337
DONT use findfirst.

Code:
private btnLogin_click()
sWhere = "[UserName]='" & me.txtUserName & "'"
vName = Dlookup("UserName","tblEmpoyees",sWhere)
vPass = Dlookup("[Password]","tblEmpoyees",sWhere)

'you could have a problem with  case of the text of either the name or pass.

select case true
case IsNull(vName)
    msgbox "Invalid UserID"
   exit sub

case  vName <> me.txtUserName
    msgbox "Invalid UserID"
   exit sub
  
case  vPAss <> me.txtPassword
    msgbox "Invalid Password"
   exit sub
end select 

docmd.openForm "frmMain"
end sub
 

vent

Registered User.
Local time
Today, 10:37
Joined
May 5, 2017
Messages
160
Thank you for the reply. Unfortunately I changed the VBA and I'm still getting the same error.
 

vent

Registered User.
Local time
Today, 10:37
Joined
May 5, 2017
Messages
160
I just decompiled the databased and now it works fine. Thank you
 

vent

Registered User.
Local time
Today, 10:37
Joined
May 5, 2017
Messages
160
Hello all

So this error still keeps coming up, even though literally a few minutes earlier, the form was working just fine. Why does this keep happening? It is rather frustrating. If anyone has advice thank you!! :banghead:
 

JHB

Have been here a while
Local time
Today, 16:37
Joined
Jun 17, 2012
Messages
7,732
If it has worked before without problem and you didn't change anything I would suggest creating a new database and import all into it.
 

Users who are viewing this thread

Top Bottom