A family of Microsoft relational database management systems designed for ease of use.
I don't understand the question.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to create a login form in MS Access 2016, Enterprise Edition. Successful login should go to an unbound form, which serves as a main menu. I am having trouble with the VBA on this...it doesn't seem to recognize the main menu object. In particular, the SET RST command seems to be sticking.
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
I don't understand the question.
Would this replace all the existing code? or just some of it?
' If rst.EOF Then
MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Login Error"
Me.txt_username.SetFocus
Else
MsgBox prompt:="Hello, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, title:="Login Successful"
DoCmd.Close acForm, "frm_login", acSaveYes
End If
Do you see it? You comment out the first line, and must also comment out the rest of this IF block.
Also: add "Option Explicit" to the top of every module, and use VBA window > Tools > Options > Require variable declaration to make it the default for new modules.
Then Debug > Compile and fix any issues (mostly: add variable declarations).
Here is the actual code
Option Compare Database
Private Sub cmd_cancel_Click()
DoCmd.Quit acQuitSaveAll
End Sub
Private Sub cmd_login_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
' mdl=forms!opening screen
If Trim(Me.txt_username.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Username should not be left blank.", buttons:=vbInformation, title:="Username Required"
Me.txt\_username.SetFocus
Exit Sub
End If
If Trim(Me.txt_password.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Password should not be left blank.", buttons:=vbInformation, title:="Password Required"
Me.txt\_password.SetFocus
Exit Sub
End If
'query to check if login details are correct
strSQL = "SELECT strName FROM tbl_login WHERE Username = """ & Me.txt_username.Value & """ AND Password = """ & Me.txt_password.Value & """"
' Set db = CurrentDb
DoCmd.OpenForm ("Opening Screen")
' Set rst = db.OpenRecordset(strSQL)
' Set rst = db.OpenForm("Opening Screen")(strSQL)
' If rst.EOF Then
MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Login Error"
Me.txt\_username.SetFocus
Else
MsgBox prompt:="Hello, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, title:="Login Successful"
DoCmd.Close acForm, "frm\_login", acSaveYes
End If
Set db = Nothing
Set rst = Nothing
End Sub
Private Sub Form_AfterUpdate()
End Sub
Private Sub txt_username_AfterUpdate()
End Sub
Note that I am a really novice user of VBA, although I have a long history with Access itself. I am trying to go line by line, ensuring that object names are correct, etc. I have a simple database that will have about 5 users, and occasional guests. I am trying to create a login screen that goes to an unbound form once successful login occurs. There is no back end (and won't be), as I'm not concerned with users modifying objects.
Thank you for your help.
Heide
Can you provide the full code with which you are experiencing difficulty. Also, is the problem raising an error, and if so, what is the error message?