In a nutshell, I have a 'new jobs' form where the 'clients name' is entered. If the client is already in the client table then that clients ID number is 'bound' into my jobs table.
However, if the client is new, then on the NotInList event the 'add new client' form is opened. I would like the name that has just been typed to be automatically passed to the 'add new client' form. I can't fathom OpenArgs sufficiently do this. Everything works except transfering the name. My code so far is below. Thanks in advance.
Private Sub ClientsName_NotInList(NewData As String, Response As Integer)
Dim strClientsName As String
Dim intReturn As Integer, varName As Variant
strClientsName = NewData
intReturn = MsgBox("Are you sure " & strClientsName & _
" is not an existing client in the list." & _
" Do you want to add this Client?", _
vbQuestion + vbYesNo, "Client Name"
If intReturn = vbYes Then
DoCmd.OpenForm FormName:="AddNewClient", _
DataMode:=acAdd, _
WindowMode:=acDialog, _
OpenArgs:=strClientsName
If IsNull(DLookup("ID", "Clients", "[ClientName] = """ & _
strClientsName & """") Then
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
Exit Sub
End If
Response = acDataErrDisplay
End Sub
My OnLoad event in the 'Add New Client' form is as follows. The field in the Clients table is ClientName.
Private Sub Form_Load()
Dim strClientsName As String
If IsNothing(Me.OpenArgs) Then Exit Sub
Else
strClientsName = Me.OpenArgs
Me![ClientName].DefaultValue = """" & strNewClientsName & """"
End If
End Sub
However, if the client is new, then on the NotInList event the 'add new client' form is opened. I would like the name that has just been typed to be automatically passed to the 'add new client' form. I can't fathom OpenArgs sufficiently do this. Everything works except transfering the name. My code so far is below. Thanks in advance.
Private Sub ClientsName_NotInList(NewData As String, Response As Integer)
Dim strClientsName As String
Dim intReturn As Integer, varName As Variant
strClientsName = NewData
intReturn = MsgBox("Are you sure " & strClientsName & _
" is not an existing client in the list." & _
" Do you want to add this Client?", _
vbQuestion + vbYesNo, "Client Name"
If intReturn = vbYes Then
DoCmd.OpenForm FormName:="AddNewClient", _
DataMode:=acAdd, _
WindowMode:=acDialog, _
OpenArgs:=strClientsName
If IsNull(DLookup("ID", "Clients", "[ClientName] = """ & _
strClientsName & """") Then
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
Exit Sub
End If
Response = acDataErrDisplay
End Sub
My OnLoad event in the 'Add New Client' form is as follows. The field in the Clients table is ClientName.
Private Sub Form_Load()
Dim strClientsName As String
If IsNothing(Me.OpenArgs) Then Exit Sub
Else
strClientsName = Me.OpenArgs
Me![ClientName].DefaultValue = """" & strNewClientsName & """"
End If
End Sub