Argument not optional

kilburfi

Registered User.
Local time
Today, 01:04
Joined
Jun 4, 2013
Messages
34
I have the following code as I have user/login tables. When the user logs on it creates a record in the relevant table, when they log off I want it to remove the user information. The code works fine for the first part but when I come to use it as part of the quit button code I am getting the above error message. I am just trying to call the module from the sub using call LogMeOff. I have tried call LogMeOff(sUser As Long) but that also gives me a different error message. Equally, when I try to run the LogMeOff function the sUser variable doesn't contain anything.

THIS BIT WORKS AT THE START
Function LogMeIn(sUser As Long)
'/Go to the users table and record that the user has logged in
'/and which computer they have logged in from
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Tbl-Users] WHERE PKEnginnerID =" & sUser)
If Not Rs.EOF Then
Rs.Edit
Rs.Fields("fldLoggedIn").Value = True
Rs.Fields("FldComputer").Value = StrComputerName
Rs.Update
End If
Rs.Close
Set Rs = Nothing

End Function

THIS DOESN'T WORK AT THE END
Function LogMeOff(sUser As Long)
'/Go to the users table and record that the user has logged out
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Tbl-Users] WHERE PKEnginnerID =" & sUser)
If Not Rs.EOF Then
Rs.Edit
Rs.Fields("fldLoggedIn").Value = False
Rs.Update
End If
Rs.Close
Set Rs = Nothing

Any help would be appreciated. I am quite new to VBA.
 
When you are calling the function you must send it the required parameter(s) in this case a Long value (sUser). So, the call would look something like this:

call LogMeOff(15)

NB: 15 is a made up number but this would be your PKEnginnerID.
FYI: A function is normally used to return a value so this maybe better off as a Sub.
 

Users who are viewing this thread

Back
Top Bottom