Subscript Out of range using OpenArgs

E

Emma

I am trying to pass values from one form to another using OpenArgs.

The values in the main form are as follows:

Job_Id (autonumber field)
cbo_Account_No (numeric field)
cbo_Account_No.Column(1) (which is the account name)

I am using the following code in the main form:

Private Sub Frame_Contract_Type_AfterUpdate()

MyOpenArgs = Me!Job_ID & "," & Me!cbo_Account_No & "," &
Me!cbo_Account_No.Column(1)

Select Case Form_frm_Tbl_Master_Jobs!Frame_Contract_Type
Case 1
DoCmd.OpenForm "Frm_Tbl_Contracts_Int", , , , acFormAdd, , MyOpenArgs
Case 2
DoCmd.OpenForm "Frm_Tbl_Contracts_Biopsy", , , , acFormAdd
Case Else
DoCmd.GoToControl "Comments"
End Select
End Sub


In the pop-up form I have the following to put these values in the
respective fields:

Private Sub Form_Open(Cancel As Integer)


'txt_Contract_Main_No = Format(Nz(DMax("[Contract_Main_No]",
"qry_Int_contracts_Main"), 0) + 1, "00000")

FK_Job_ID = Split(MyOpenArgs, ",")(0)
txt_Account_No = Split(MyOpenArgs, ",")(1)
Contract_Account_Name = Split(MyOpenArgs, ",")(2)

End Sub

However, when I make my selection from the option frame, I get a subscript
out of range error and it looks like OpenArgs are not being passed to the new
form. Can anyone tell me how to fix this?

Thank you!
 
R

Rob Oldfield

....and you'd be better off just running the split command once...

dim arrOArgs() as string
arrOArgs=split(me.openargs,",")
FK_Job_ID = arrOArgs(0)
'or possibly FK_Job_ID = cint(arrOArgs(0))
txt_Account_No = arrOArgs(1)
Contract_Account_Name = arrOArgs(2)


Duane Hookom said:
Where are you setting the value of "MyOpenArgs" in the opened form?

--
Duane Hookom
MS Access MVP
--

Emma said:
I am trying to pass values from one form to another using OpenArgs.

The values in the main form are as follows:

Job_Id (autonumber field)
cbo_Account_No (numeric field)
cbo_Account_No.Column(1) (which is the account name)

I am using the following code in the main form:

Private Sub Frame_Contract_Type_AfterUpdate()

MyOpenArgs = Me!Job_ID & "," & Me!cbo_Account_No & "," &
Me!cbo_Account_No.Column(1)

Select Case Form_frm_Tbl_Master_Jobs!Frame_Contract_Type
Case 1
DoCmd.OpenForm "Frm_Tbl_Contracts_Int", , , , acFormAdd, ,
MyOpenArgs
Case 2
DoCmd.OpenForm "Frm_Tbl_Contracts_Biopsy", , , , acFormAdd
Case Else
DoCmd.GoToControl "Comments"
End Select
End Sub


In the pop-up form I have the following to put these values in the
respective fields:

Private Sub Form_Open(Cancel As Integer)


'txt_Contract_Main_No = Format(Nz(DMax("[Contract_Main_No]",
"qry_Int_contracts_Main"), 0) + 1, "00000")

FK_Job_ID = Split(MyOpenArgs, ",")(0)
txt_Account_No = Split(MyOpenArgs, ",")(1)
Contract_Account_Name = Split(MyOpenArgs, ",")(2)

End Sub

However, when I make my selection from the option frame, I get a subscript
out of range error and it looks like OpenArgs are not being passed to the
new
form. Can anyone tell me how to fix this?

Thank you!
 

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