Error: Argument Not Optional

Joined
Jan 13, 2015
Messages
1
Reaction score
0
I have a form with multiple users. I'm trying to set it so there is a pop up if a record is open that's locked by another user for editing. I know you can set the Editing functions in the menu but that will only show you a record is locked after you go to save all your changes. Here's what i have:

Function IsLocked(rs As Recordset, UserName As String, MachineName As String)

' Accepts: a recordset and two string variables
' Purpose: determines if the current record in the recordset is locked,
' and if so who has it locked.
' Returns: True if current record is locked (and sets UserName
' and MachineName to the user with the lock). False if the
' record isn't locked.
' From: Building Applications Chapter 12

Dim ErrorString As String
Dim MachineNameStart As Integer

IsLocked = False
On Error GoTo IsLockedError

rs.Edit 'Try to edit the current record in the recordset.
rs.MoveNext
rs.MovePrevious
Exit Function 'No error, so return False.

IsLockedError:
If Err = 3260 Then 'Record is locked -- parse error string.
ErrorString = Error$
UserName = Mid$(ErrorString, 44, InStr(44, ErrorString, "'") - 44)
If UserName = "" Then UserName = "(unknown)"
MachineNameStart = InStr(43, ErrorString, " on machine ") + 13
MachineName = Mid$(ErrorString, MachineNameStart, Len(ErrorString) - MachineNameStart - 1)
If MachineName = "" Then MachineName = "(unknown)"
IsLocked = True
End If
Exit Function
End Function


Trying to run the function "On Current" as below:


Private Sub Form_Current()
Call Module1.IsLocked
End Sub

When I try to run, I get an error that says Argument not optional.

I'm not familiar with this nor am I very familiar with running fuctions through subs. Any help is greatly appreciated!
 
Last edited:
Back
Top