Open Args

  • Thread starter Thread starter Ayala
  • Start date Start date
A

Ayala

Hi, I know that the Open Args can help me to send a value
when a form is going to open (or not?)

Well, I am not sure on how to use it.

I need a user to pick a date and a name in a previous form
called frmDate

Then open a new form where the user have to fill the
activities for this date and name. I don't want the user
to type again the date and name, can I use the open args?

how?

thx.
 
You can, but I personally consider that a "workaround" and not the best
method for achieving what you want. Instead, just set those values from your
calling form:

(in the form where you pick the date/name)
DoCmd.OpenForm "NewForm",,,,acFormAdd
Forms!NewForm!DateField = Me.DateField
Forms!NewForm!NameField = Me.NameField

Note that you'll have to change the names to reflect those in your project.
Also, the acFormAdd argument in the DoCmd action may be in the wrong place
.... the Intellisense will tell you where it needs to be, however.
 
OpenArgs passes a single string value to the form being opened.

You access OpenArgs in the Form_Open event.

If you want to pass two values via OpenArgs you will have to delimit them in
the string you pass and then parse the string to separate them. If you are
using Access2000 or XP you can use Split to put the values into a string
array.

The code below assumes you pass the OpenArgs in the order "Date, Name"

Private Sub Form_Open(Cancel As Integer)
Const DELIM = ","
Dim Argv() As String
Dim datArg as Date
Dim strName as String

If OpenArgs <> "" Then
Argv = Split(OpenArgs, DELIM)
datArg = CDate(Argv(0))
strName = Argv(1)
End If
End Sub

Rod Scoullar
 
Hi Scott,

Though I agree that it is not always the best method, if you are opening a
form using acdialog for the windowmode you either have to do it this way or
use code within the dialog form to pull from the calling form. I've done it
both ways for dialog forms depending on the situation.
 
Using a button to open a new form, the syntax for using Open Args would look like
(use your form and control names

Private Sub Command4_Click(
On Error GoTo Err_Command4_Clic

Dim stDocName As Strin
Dim strOpenArgs As Strin

' get the two fields and mash them together ('mash' is a technical term.. ;-
strOpenArgs = Forms!FORM1!DateField & "," & Forms!FORM1!NameFiel

stDocName = "frmFormToOpen

' NOTE: six commas are require
DoCmd.OpenForm stDocName, , , , , , strOpenArg

Exit_Command4_Click
Exit Su

Err_Command4_Click
MsgBox Err.Descriptio
Resume Exit_Command4_Clic

End Su

Then in the form opened, use code (see Rod Scoullar's post) to parse the Open Args string

You could parse the Open Args string and set the controls in the data entry form directly

If OpenArgs <> "" The
Argv = Split(OpenArgs, DELIM
Me.OpenDate = CDate(Argv(0)
Me.NewName = Argv(1
End I

HT

Stev
 
Back
Top