Solved Passing values to popup using OpenArgs (1 Viewer)

mib1019

Member
Local time
Today, 01:59
Joined
Jun 19, 2020
Messages
88
Thanks again, in advance, for your help. I'll have another couple of questions on this after this little issue gets resolved.

I have a button on a form that opens a popup form to get a list of dates. There are four values to be passed to the popup. Here is the code for button click event:
Code:
Private Sub cmdOpenDateSelector_Click()
On Error GoTo cmdOpenDateSelector_Click_Err
      
    Dim StartDate, EndDate As Date
    Dim IODetailID As Long
    Dim Program As String
    StartDate = Me.txtStartDate
    EndDate = Me.txtEndDate
    IODetailID = Me.txtDetailID
    Program = Me.txtProgram


    If Not IsNull(Me.txtStartDate) And Not IsNull(Me.txtEndDate) Then
        Dim strOpenArgs As String
        strOpenArgs = IODetailID & ";" & StartDate & ";" & EndDate & ";" & Program
        
        
        DoCmd.OpenForm "Copy of Date Select Dialog", , , , , acDialog, strOpenArgs
    Else
        MsgBox "I need a date range."
    End If

cmdOpenDateSelector_Click_Exit:
    Exit Sub

cmdOpenDateSelector_Click_Err:
    MsgBox Error$
    Resume cmdOpenDateSelector_Click_Exit

End Sub

And here is the code for the Load Event on the popup form.

Code:
Private Sub Form_Load()
'populate the fields on the popup form
    
    Dim strOpenArgs As Variant
    
    strOpenArgs = Split(Me.OpenArgs, ";")
      
    Me!txtDetailID = strOpenArgs(0)
    Me!txtStart = strOpenArgs(1)
    Me!txtEnd = strOpenArgs(2)
    Me!txtIODetailProgram = strOpenArgs(3)
      
End Sub

In opening the popup I get the attached error message. The code doesn't crash, so I don't know where it's hanging up.

Everything looks good. I verified it with a msgbox to see the full value of OpenArgs in the button code. And debug.print strOpenArgs(n) also showed the four values as being correct. The popup form fields correctly fill with the data.

Hope that was enough info for your advice.
MIB1019
 

Attachments

  • Capture.PNG
    Capture.PNG
    6.3 KB · Views: 238

mib1019

Member
Local time
Today, 01:59
Joined
Jun 19, 2020
Messages
88
Gasman, I get all the split values correctly on debug.print. And it does fill the values in the various textboxes on the popup form, with a possible exception.

In trying to find the error, I open the form without the OnLoad event. I can fill in txtStart, txtStart, txtIODetailProgram with no issues, dates and text. When I put a value in txtDetailID field I get a 'subscript out of range' error. That must be where the error message is coming from on the OnLoad event.

So I'm still stuck.
MIB1019
 

mib1019

Member
Local time
Today, 01:59
Joined
Jun 19, 2020
Messages
88
I just figured it out. Had to convert the strings back to dates and numbers with CDate and CLng
MIB1019
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:59
Joined
Sep 21, 2011
Messages
14,253
Well the example shown uses an array () and that is how I would use it, as I know no better?
You could have just used Split(OpenArgs,";")(0) etc and forget about the strOpenArgs ?
 

Users who are viewing this thread

Top Bottom