Populate multiple fields with OpenArgs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

Is it possible to populate multiple fields with OpenArgs? Say I have 3
fields populated in form1, and I want those 3 fields to be populated in
form2. Can I use the OpenArgs to do this?
 
I tried to pass multiple parameters using a delimiter as follows:

In my first form. Job_Type is a combo box

Private Sub Job_Type_AfterUpdate()

Select Case Me!Job_Type

Case "New Contract"
DoCmd.GoToControl "Frame_Contract_Option"
Case "Rental"
MyOpenArgs_Rental = Me!Account_No(0) & "-" & Me!Account_No(1) & "-"
& Me!Account_No(4) & "-" & Me!Account_No(5) & "-" & Me!Account_No(6) & "-" &
Me!Account_No(7)
'Account No, Name, address 1, address 2, city, state, and zip
DoCmd.OpenForm "frm_Rental_Detail", acNormal, Qry_Rental_Detail, ,
acFormAdd, acWindowNormal, MyOpenArgs_Rental
Case "Evaluation"
DoCmd.OpenForm "frm_Eval_Detail", acNormal, Qry_Eval_Detail, ,
acFormAdd, acWindowNormal, Me!Account_No
Case Else
DoCmd.GoToControl "Rep_name"

End Select


End Sub

In my second form, I have the following code in the "OnLoad" event.

Private Sub Form_Load()

Me!Rental_Acct_No = Split(Me.OpenArgs, "-")(0)
Me!Rental_Acct_Name = Split(Me.OpenArgs, "-")(1)
Me!Rental_Acct_Address_1 = Split(Me.OpenArgs, "-")(2)
Me!Rental_Acct_Address_2 = Split(Me.OpenArgs, "-")(3)
Me!Rental_Acct_City = Split(Me.OpenArgs, "-")(4)
Me!Rental_Acct_State = Split(Me.OpenArgs, "-")(5)
Me!Rental_Acct_Zip = Split(Me.OpenArgs, "-")(6)

End Sub


I am getting the following error.

"Property let procedure not defined and property get procedure did not
return an object."

Why am I getting this error?

Thank you,
 
Hi all,

Is it possible to populate multiple fields with OpenArgs? Say I have 3
fields populated in form1, and I want those 3 fields to be populated in
form2. Can I use the OpenArgs to do this?

With a bit of work. You can only pass one OpenArgs argument, but it
can be a delimited text string containing three values; for instance
you could set OpenArgs to the string "3;98;Cheese" and parse it apart
in the target form's Open event (using the Split function, see the
online help).


John W. Vinson[MVP]
 
"Property let procedure not defined and property get procedure did not
return an object."

Why am I getting this error?

The Load event is, I think, too early - use the form's Open event
instead.

John W. Vinson[MVP]
 
Emma said:
I tried to pass multiple parameters using a delimiter as follows:

In my first form. Job_Type is a combo box

Private Sub Job_Type_AfterUpdate()

Select Case Me!Job_Type

Case "New Contract"
DoCmd.GoToControl "Frame_Contract_Option"
Case "Rental"
MyOpenArgs_Rental = Me!Account_No(0) & "-" & Me!Account_No(1) & "-"
& Me!Account_No(4) & "-" & Me!Account_No(5) & "-" & Me!Account_No(6) & "-" &
Me!Account_No(7)
'Account No, Name, address 1, address 2, city, state, and zip
DoCmd.OpenForm "frm_Rental_Detail", acNormal, Qry_Rental_Detail, ,
acFormAdd, acWindowNormal, MyOpenArgs_Rental
Case "Evaluation"
DoCmd.OpenForm "frm_Eval_Detail", acNormal, Qry_Eval_Detail, ,
acFormAdd, acWindowNormal, Me!Account_No
Case Else
DoCmd.GoToControl "Rep_name"

End Select


End Sub

In my second form, I have the following code in the "OnLoad" event.

Private Sub Form_Load()

Me!Rental_Acct_No = Split(Me.OpenArgs, "-")(0)
Me!Rental_Acct_Name = Split(Me.OpenArgs, "-")(1)
Me!Rental_Acct_Address_1 = Split(Me.OpenArgs, "-")(2)
Me!Rental_Acct_Address_2 = Split(Me.OpenArgs, "-")(3)
Me!Rental_Acct_City = Split(Me.OpenArgs, "-")(4)
Me!Rental_Acct_State = Split(Me.OpenArgs, "-")(5)
Me!Rental_Acct_Zip = Split(Me.OpenArgs, "-")(6)

End Sub


I am getting the following error.

"Property let procedure not defined and property get procedure did not
return an object."

Why am I getting this error?

Thank you,
:

Emma,

In the Job_Type_AfterUpdate() code, you need to use the .Column() property.
Change the line

MyOpenArgs_Rental = Me!Account_No(0) & "-" & Me!Account_No(1) & "-" &
Me!Account_No(4) & "-" & Me!Account_No(5) & "-" & Me!Account_No(6) & "-" &
Me!Account_No(7)

to

MyOpenArgs_Rental = Me!Account_No.Column(0) & "-" & Me!Account_No.Column(1) &
"-" & Me!Account_No.Column(4) & "-" & Me!Account_No.Column(5) & "-" &
Me!Account_No.Column(6) & "-" & Me!Account_No.Column(7)


In the second form, change the Form_Load code to:

Private Sub Form_Load()
Dim MyOpenArgsArray

MyOpenArgsArray = Array(6)

MyOpenArgsArray = Split(MyOpenArgs_Rental, "-")

Me!Rental_Acct_No = MyOpenArgsArray(0)
Me!Rental_Acct_Name = MyOpenArgsArray(1)
Me!Rental_Acct_Address_1 = MyOpenArgsArray(2)
Me!Rental_Acct_Address_2 = MyOpenArgsArray(3)
Me!Rental_Acct_City = MyOpenArgsArray(4)
Me!Rental_Acct_State = MyOpenArgsArray(5)
Me!Rental_Acct_Zip = MyOpenArgsArray(6)

End Sub



The Split() function fills an array, so first you have to declare an array.
Then you can fill the controls from the array.

Not to argue with John Vinson, I would use the Load event. The order of events
for a form is (from Help)

Open -> Load -> Resize -> Activate -> Current

"The Open event occurs when a form is opened, but before the first record is
displayed."

"The Load event occurs when a form is opened and its records are displayed.
By running a macro or an event procedure when a form's Load event occurs, you
can specify default settings for controls, or display calculated data that
depends on the data in the form's records."



HTH
 
Okay, I tried this but now I'm getting a subscript out of range error. This
is my code in my first form.

Private Sub Job_Type_AfterUpdate()
Dim MyOpenArgs As String

MyOpenArgs = Me!Job_ID & "-" & Me!Account_No

Select Case Me!Job_Type

Case "New Contract"
DoCmd.GoToControl "Frame_Contract_Option"

Case "Rental"
DoCmd.OpenForm "frm_Rental_Detail", acNormal, Qry_Rental_Detail, ,
acFormAdd, acWindowNormal, MyOpenArgs
Case "Evaluation"

DoCmd.OpenForm "frm_Eval_Detail", acNormal, Qry_Eval_Detail, ,
acFormAdd, acWindowNormal, MyOpenArgs
Case Else
DoCmd.GoToControl "Rep_name"

End Select

End Sub

In my second form I have:

Private Sub Form_Load()

FK_Master_Job_ID = Split(MyOpenArgs, "-")(0)
Rental_Acct_No = Split(MyOpenArgs, "-")(1)


End Sub

Why am I getting the subscript out of range error?
 
Back
Top