Unpacking OpenArgs

  • Thread starter Thread starter John Pritchard
  • Start date Start date
J

John Pritchard

Is there a good way to pass many parameters to a form ?
I've used the openargs string BUT cann't find a good way
to unpack it. As an old 'C' programmer I was hoping for
something like strtok() then I could pass "arg1,arg2,arg3"
for example.

Incidently how are strings implemented in BASIC they
don't appear to be arrays of char ?
 
Is there a good way to pass many parameters to a form ?
I've used the openargs string BUT cann't find a good way
to unpack it. As an old 'C' programmer I was hoping for
something like strtok() then I could pass "arg1,arg2,arg3"
for example.

Incidently how are strings implemented in BASIC they
don't appear to be arrays of char ?

Assuming you are using a newer version of Access that includes the
Split() function.

First Copy and Paste the following Function into a Module:

Public Function ParseText(TextIn As String, X) As Variant
On Error Resume Next
Dim var As Variant
var = Split(TextIn, ",", -1)
ParseText = var(X)

End Function
========

To pass an OpenArgs when opening the second form:

DoCmd.OpenForm "FormName", , , , , , "Hello,GoodBy,Mary,Lamb"

or if you are passing field data:

DoCmd.OpenForm "FormName", , , , , ,[FieldA] & "," & [FieldB] & "," &
..... etc.

To read the OpenArgs in the second form,
code the second form's Load event:

If Not IsNull(Me.OpenArgs) Then
Dim intX as integer
Dim intY As Integer
intX = InStr(Me.OpenArgs, ",")
Do While intX <> 0
intY = intY + 1
intX = InStr(intX + 1, Me.OpenArgs, ",")
Loop

For intX = 0 To intY
' Change the below line to use the OpenArgs however you want to.
Debug.Print ParseText(Me.OpenArgs, intX)
Next intX

End If

If your version of Access does not have Split(), you can use InStr(),
Left(), and Mid() functions to split the OpenArgs into it's various
parts.
 
Back
Top