Information about the OpenArgs property

J

John S. Ford, MD

Does anyone know of a good online reference to using the OpenArgs property
for passing values from one form to another?

John
 
D

Dennis

John,

I'm still learning, but here is what I know. The use of the OpenArgs is
very easy.

From the calling process use something like

Dim strOpenArgs As String

strDocName = "rptOtherMem"
strOpenArgs = "Other"
DoCmd.OpenReport strDocName, acViewPreview, , , acWindowNormal,
OpenArgs:=strOpenArgs

You just pack the value strOpenArgs with you data fields. If you want to
have multiple data fields, you will have to put your own seperator in place
(such as comma or semi-colon, etc.).

In the called program in the Form's On Load event or the Report's On Open
Event, put the following code in:



Dim strOpenParms As String

strOpenParms = Nz(Me.OpenArgs, "")

I put the NZ arount the OpenArgs incase the calling program did not pass any
parameters.

If you passed multiple parameters in OpenArgs, you will need to extract them
from the OpenArgs string.

I hope this helps. Good luck.
 
T

Tony Toews [MVP]

Dennis said:
If you want to
have multiple data fields, you will have to put your own seperator in place
(such as comma or semi-colon, etc.).

Split function helps separate those out on the recipient form.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
D

Douglas J. Steele

Dennis said:
You just pack the value strOpenArgs with you data fields. If you want to
have multiple data fields, you will have to put your own seperator in
place
(such as comma or semi-colon, etc.).

I usually pass a string along the lines of:

variable1=value1;variable2=value2;variable3=value3

so perhaps

CustName=Smith;Product=Flanges;LastOrder=2009-02-22

In the form's Load event (or even the Open event), my code will be something
like:

Dim lngLoop As Long
Dim varCurrArg As Variant
Dim varArguments As Variant

If IsNull(Me.OpenArgs) = False Then
' Split the arguments passed on the semi-colons
varArguments = Split(Me.OpenArgs, ";")
For lngLoop = LBound(varArguments) To UBound(varArguments)
' Looking at a particular argument, split on the equal sign.
varCurrArg = Split(varArguments(lngLoop), "=")
' Make sure that the argument passed is formatted correctly
' (i.e.: that it's got one equal sign in it)
If UBound(varCurrArg) = 1 Then
Select Case varCurrArg(0)
Case "CustName"
Me.CustName = varCurrArg(1)
Case "Product"
Me.Product = varCurrArg(1)
Case "LastOrder"
Me.LastOrder = varCurrArg(1)
Case Else
MsgBox "Sorry, I don't know what to do with " & _
varCurrArg(0) & " in " & Me.OpenArgs
End Select
Else
Msgbox "Invalid argument " & varArguments(lngLoop) & _
" in " & Me.OpenArgs
End If
Next lngLoop
End If
 
K

Ken Sheridan

Some years ago Stuart McCall developed a module for passing a multiple
arguments as a value list via the OpenArgs mechanism. I later expanded this
in response to a request by another user to enable it to be used to also pass
named arguments. You'll find a demo incorporating the module and a couple of
forms to try it out at:


http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=24091&webtag=ws-msdevapps


BTW reports also support the OpenArgs property, since Access 2002 at least,
not sure about 2000.

Ken Sheridan
Stafford, England
 
R

Roger Carlson

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top