Values won't pass between forms (1 Viewer)

Thumper75

Registered User.
Local time
Today, 04:34
Joined
Feb 6, 2017
Messages
37
I have a project I'm working on and seem to be stuck. I think I'm close but the pass through is not working.

I'm working with two forms. Sign off "frm_Sign_Off" and 8130 "frm_8130". The 8130 form is opened by clicking a button. The goal is to auto populate two critical values from the Sign Off form to the 8130 form. The two values are Logpg and tail.

I open the 8130 form from the button using the following code.

Code:
Private Sub btn_8130_Click()
 
Dim lp As String
Dim reg As String
Dim pass As String

lp = Me.Logpg.Value
reg = Me.tail.Value
pass = lp & ";" & reg

DoCmd.OpenForm "frm_8130", acNormal, , , acFormAdd, acWindowNormal, pass

End Sub

If I understand it correctly, the "pass" should be the OpenArgus Parameter. What I am not sure of is if I have to code the variables differently or not, or if I'm just making a mistake here.

When the 8130 form opens, I am using the OnLoad event to fire the transfer of the arguments and populate the fields using the following code.

Code:
Private Sub Form_Load(Canel As Integer)

Dim Args As String

If Not IsNull(Me.OpenArgs) Then
    Args = Split(Me.OpenArgs, ";")
    Me.Logpg = argstrg(0) 'This should be the log page passed from the sign-off form
    Me.reg = argstrg(1) 'This should be the tail number passed from the sign 0ff form
End If

End Sub

The code, as I understand it, looks right and should work. The form opens but the parameters do not populate. I am looking for any direction here working with this code or if someone can point out what I am doing wrong.

Thanks,
Vince
 

JHB

Have been here a while
Local time
Today, 10:34
Joined
Jun 17, 2012
Messages
7,732
Try add () to the declared variable:
Code:
Dim Args[B][COLOR=Red]()[/COLOR][/B] As String
You also reefer to a not declared variable:
Code:
Me.Logpg = [B][COLOR=Red]argstrg[/COLOR][/B](0)
It should be Args(0) and Args(1)
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:34
Joined
Jan 20, 2009
Messages
12,849
As JHB pointed out, the Split function requires an array variable.

The other issue is that OpenArgs is a Null String rather than a Null if no value is passed so should be tested against a Null String.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:34
Joined
May 7, 2009
Messages
19,175
The is somewhat right. Need to declare Arg as array or Variant.
Need to use nz()

If nz(me.openargs, vbnullstring)<>vbnullstring


When you dont pass any arg, its vallue is null and not vbnullstring.
 

Thumper75

Registered User.
Local time
Today, 04:34
Joined
Feb 6, 2017
Messages
37
JHB! Thanks that was helpful. I'm still missing something though because its not splitting the string. I went back and tried using message boxes to validate and test the separation of the values. The Args(0) seems to return both log page number and tail number as a continuous string then with the second message box I am getting an error that it is out of range. So my assumption is that I have done something incorrect in splitting the string.

Code:
Private Sub Form_Load()

Dim Args() As String
Args() = Split("Me.OpenArgs", "|", 2)
'MsgBox "The Form has opened and loaded.", vbOKOnly


'Me.Logpg.Value = Me.OpenArgs
If Not IsNull(Me.OpenArgs) Then
    'Args() = Split("Me.OpenArgs", "|")
    'MsgBox "Log page number is " & Args(0)
    'MsgBox "Tail number is " & Args(1)
    Me.Logpg = Args(0)
    Me.reg = Args(1)
End If



'Dim lp As String

'If Not IsNull(Me.OpenArgs) Then
    'MsgBox "The opening arguements are " & pass, vbOKOnly
'Else
    'MsgBox "There are no Opening Aruguments detected"
    
    'pass = Split(Me.OpenArgs, ";")
    'Me.Logpg.Value = lp  'This should be the log page passed from the sign-off form
    'Me.reg.Value = reg  'This should be the tail number passed from the sign 0ff form
'End If

End Sub

Please forgive me, I know the code looks sloppy, I will clean it up just as soon as I get the functions to work. So I am making headway but I'm just short of the finish line. By the way guys, these were great comments and very helpful. I'm a little confused by the last two prior to this post.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:34
Joined
Jan 20, 2009
Messages
12,849
I'm a little confused by the last two prior to this post.

Arnelg was pointing out that the return from the Split function can go to either an array (a variable name with () after it) or a Variant (which is a complex structure that can hold an array).

Also he notes that I was mistaken about the nature of an empty OpenArgs. Apparently it is a Null after all, not an empty string. Sorry for my mistake.
 

JHB

Have been here a while
Local time
Today, 10:34
Joined
Jun 17, 2012
Messages
7,732
I don't why you certainly change it to the below, then it is wrong:
Code:
Args() = Split("Me.OpenArgs", "|", 2)
Correct is, (just copy the line, don't type it in!):
Code:
Args = Split(Me.OpenArgs, "|")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:34
Joined
May 7, 2009
Messages
19,175
Remove this line, youre not sure if an arg is passed. And you already have a validation for it:

Args() = Split("Me.OpenArgs", "|", 2)
 

Users who are viewing this thread

Top Bottom