Just off the top of my head and probably not the most elegant way, but I think I would put a hidden table in the dB, let's call it "tblLog" for the moment. Create a new form - let's call it "frmLog" and hide it as well. Now when your dB opens up, you should use your autoexec macro (or other startup form if you prefer) to open frmLog in hidden mode. The OnOpen of the new form will put an entry into your dB for the person logging on by use of this code:
Private Sub Form_Open()
If Len(Nz(DLookup("[UserName]","[tblLog]","[tblLog].[UserName] = '" & Environ$("UserName" & "'", "") = 0 Then
DoCmd.RunSQL "INSERT INTO tblLog( UserName ) SELECT '" & Environ$("UserName" & "' As UserName_ FROM
tblLog;"
Else
Msgbox "You are already logged into this application!",vbCritical+vbOKOnly,"Multiple Log-ins"
Application.Quit
End If
End Sub
Now, for the form close, put this:
Private Sub Form_Close()
DoCmd.RunSQL "DELETE * FROM tblLog WHERE tblLog.UserName = '" & Environ$("UserName" & "'"
Exit Sub
Sorry for any type-O's as I'm writing this free-hand... Kyle
Private Sub Form_Open()
If Len(Nz(DLookup("[UserName]","[tblLog]","[tblLog].[UserName] = '" & Environ$("UserName" & "'", "") = 0 Then
DoCmd.RunSQL "INSERT INTO tblLog( UserName ) SELECT '" & Environ$("UserName" & "' As UserName_ FROM
tblLog;"
Else
Msgbox "You are already logged into this application!",vbCritical+vbOKOnly,"Multiple Log-ins"
Application.Quit
End If
End Sub
With:
Private Sub Form_Open()
If Len(Nz(DLookup("[UserName]","[tblLog]","[tblLog].[UserName] = '" & Environ$("UserName" & "'", "") = 0 Then
DoCmd.RunSQL "INSERT INTO tblLog( UserName ) SELECT TOP 1 '" & Environ$("UserName" & "' As UserName_ FROM
tblLog;"
Else
Msgbox "You are already logged into this application!",vbCritical+vbOKOnly,"Multiple Log-ins"
Application.Quit
End If
End Sub Kyle
Thanks for the assistance, though it doesn't seem to work as it appends 0 rows. I don't know whether Access version (Access2000) or Windows version (Windows 2000) has to do anything with this.
Oh yeah, that. In order to run and append query you need to have a table to base it off of, and since the table here doesn't have any records, the query won't give any records. So add an empty entry and then try this. Kyle
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.