First things first, don't use "Name" as a field name, in your case change it
to "EmployeeName". Name is a reserved word in Access and it can cause you
grief later on. Also change the "IN" field to "LoggedIn"
In the logon form use a combo box that lists the users' names so the user
can then select their name instead on typing it. Use 2 columns in the combo
box: lngEmpID, EmployeeName. Set the combo box's column count to 2 and the
column width to 0cm;3.5cm. This will hide the first column and display the
second. Also make sure there is a text box for the user to type in the
password.
Behind the button you're going to use to log the user in copy the following
code.
(I'm using "tbl" as the table name, change this to the actual name of the
table)
' **************CODE START 1 *************************
Dim db as DAO.Database
Dim rst as DAO.Recordset
Dim strSQL as String
On Error GoTo LogInErr
strSQL = "SELECT lngEmplD, Password, LoggedIn " _
& "FROM tbl " _
& "WHERE lngEmpID = " & Me!ComboBoxName & ";"
Set db = CurrentDB
Set rst = db.OpenRecordset(strSQL)
With rst
If .RecordCount = 0 Then
MsgBox "Please select a user"
Else
If !Password <> Me!PasswordTextBoxName Then
MsgBox "Incorrect password", vbCritical
Else
If !LoggedIn = True Then
MsgBox "This user is already logged in"
Else
!LoggedIn = True
End If
End If
End If
End With
LogInExit:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
LogInErr:
MsgBox "Error # " & Err.Number & " has occured." & vbcrlf _
& vbcrlf & Err.Description
Resume LogInExit
'***************CODE END 1***********************************
To log the person off place the following code behind the Log Off button.
'**************CODE START 2 *********************************
Dim db as DAO.Database
Dim rst as DAO.RecordSet
Dim strSQL as String
On Error GoTo LogOutErr
strSQL = "SELECT lngEmplD, LoggedIn " _
& "FROM tbl " _
& "WHERE lngEmpID = " & Me!ComboBoxName & ";"
Set db = CurrentDB
Set rst = db.OpenRecordset(strSQL)
With rst
If .RecordCount = 0 Then
MsgBox "This user doesn't exist or is not logged in."
Else
!LoggedIn = False
MsgBox "User successfully logged out."
End If
End With
LogOutExit:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
LogOutErr:
MsgBox "Error # " & Err.Number & " has occured." & vbcrlf _
& vbcrlf & Err.Description
Resume LogOutExit
'*********************CODE END 2 ***********************************
"Mark" <te********@webmail.co.za> wrote in message
news:40**************************@posting.google.c om...
Hi all I can write basic VBA code.
I have on problem, I have a tbl with the following fields:
lngempID - Name - Password - IN
This is for a logon form once the user logon I want the field IN to
mark the current users as logedon (true)
I need to open recordsets, that I know but have tried everything.
Please Help me!!!!!
On the Main MDIFORM I need a button to log user off and change the IN
status to false.
South Africa