Forum Discussion
2 of the 3 works
Where are these lines of code running? How are they triggered?
Is the form called "frmLogin" actually open when this line runs? (It must be open to work.)
Does it have a valid value in it when the line of code runs?
Is Forms![frmLogin].[UserName] a bound control?
- Francisco_CuartasOct 26, 2021Copper ContributorHello George, this is the code that opens the logbook entry
stDocName = "frmLogbookEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
Forms![frmLogbookEntry].[LogData] = [UserName] & " On site,and Logged In ." ==the UserName does not work, the other part does
Forms![frmLogbookEntry].[LogType] = "logIn" ==This line works
'Forms![frmLogbookEntry].[OfficerName] = Me.[UserName]== Does not work
DoCmd.Save
DoCmd.Close- George_HepworthOct 26, 2021Silver Contributor
Please post the COMPLETE procedure, starting with the declaration as Private or Public and ending with the close, End Sub or End Function, not snippets from it.
Also, please confirm that this code runs on some event in the form named frmLogin. Which event? A command button click?
Again, it's also useful to have answers to my specific questions, including the actual value in the control called UserName on the form called [frmLogin]. Is UserName a bound control? What kind of control is it? Thank you.PS: Maybe in this case actual screenshots of the two forms would also be helpful. Thanks again.
- Francisco_CuartasOct 26, 2021Copper ContributorPrivate Sub Command1_Click()
Dim rs As Recordset
Dim Security, UserName As String
Dim Auth As Variant
On Error GoTo Err:
Set rs = CurrentDb.OpenRecordset("tblUser", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.UserName & "'"
If IsNull(Me.TxtSiteName) Then
Me.TxtSiteName.SetFocus
MsgBox "Insert Site Name.", vbCritical, "Login"
Exit Sub
End If
If rs.NoMatch = True Then
Me.UserName.SetFocus
MsgBox "Wrong User Name", vbCritical, "Login"
Exit Sub
End If
If IsNull(Me.txtPassword) Then
Me.txtPassword.SetFocus
MsgBox "Insert Password.", vbCritical, "Login"
Exit Sub
End If
If rs!UserSecurity <> Me.txtPassword Then
MsgBox "Wrong Password, Please try again.", vbCritical, "Login"
Else
Auth = DLookup("UserManage", "tblUser", "UserName='" & Me.UserName & "'")
DoCmd.OpenForm "frmMain", acNormal, , "UserName='" & Me.UserName & "'"
DoCmd.OpenForm "frmLoggedIn", acNormal, , "UserName='" & Me.UserName & "'"
Forms!frmMain.cmdLogOut.SetFocus
If Auth = 0 Then
Forms!frmMain.cmdAddNewUser.Visible = False
Forms!frmMain.cmdUsers.Visible = False
Else
Forms!frmMain.cmdAddNewUser.Visible = True
Forms!frmMain.cmdUsers.Visible = True
End If
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.Close acForm, "frmBackGround", acSaveNo
stDocName = "frmLogbookEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
Forms![frmLogbookEntry].[LogData] = [UserName] & " On site,and Logged In ."
Forms![frmLogbookEntry].[LogType] = "logIn"
'Forms![frmLogbookEntry].[OfficerName] = Me.[UserName]
DoCmd.Save
DoCmd.Close
End If
Exit Sub
The UserName it is Unbound.