Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difficulties with OpenArgs

Status
Not open for further replies.

keithgi

Technical User
Feb 1, 2002
20
GB
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
 
Here is how I send the arguments. The open args is the 7th parameter, I am not sure how your syntax matches up.

DoCmd.OpenForm DocName, , , , , , MyArgs

Another thing you could do is check what is being passed by a debug.print, then do a control G to view the debug window.

Debug.Print "These are my args = "; Me.OpenArgs
If IsNothing(Me.OpenArgs) Then Exit Sub
Else
 
Have you considered using a global variable to pass the new name?

Public NewName as String

You can set and test the variable before calling the form.

mac
 
Thanks mac and cmmrfrds.

Where would I put the debug.print code?

Mac, could you expand on your recommendation as Access is still somewhat new to me, and so far I've only got as far as I have by looking at others people's working code and adapting to suit my database.

Thanks
 
Keith, select modules from the tabs. The default is Module1 which you can rename if you wish. Select Design mode for viewing. Under the options explicit statement type:

Public strClientsString as String

This string will be available throughout the database and accessible from other databases. I use these public variables often in my programs to pass variables between forms. Puriest will tell us to use Let and Get statements; but, I'm content with public variables.

mac
 
The Debug.print statement would go into the OnOpen Event of the Form you are opening.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top