Use form values in another form (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:38
Joined
May 21, 2018
Messages
8,463
* In textbox5 of form2 I need the value that the user inserted in textbox1 of form1.
* In textbox6 of form2 I need the value that the user inserted in textbox2 of form1.
If I set the value of the form2 textboxes in the form2 load event I have
As far as I can tell, it should do exactly that. You are passing in those values as openargs, you split them out, you assign them to 5 and 6.

The error I get now is Run-time error '94': Invalid use of Null, in line Me.textbox5= (cdbl(split(openargs,":")(0)))
The form is looking for open args and I am guessing you opened the form directly. I always put in a check to make sure open args was passed
Code:
if trim(me.openargs & " ") <> "" then  ' check open args passed
    if isnumeric(split(me.openargs,":")(0)) then me.textbox5= (cdbl(split(openargs,":")(0))) ' check you passed a number
    if isnumeric(split(me.openargs,":")(1)) then Me.textbox6 =(cdbl(split(openargs,":")(1)))
end if

Check my "()" to make sure I counted correctly.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:38
Joined
Feb 19, 2013
Messages
16,553
T
he error I get now is Run-time error '94': Invalid use of Null, in line Me.textbox5= (cdbl(split(openargs,":")(0)))
could also be that there is no value in form1, textbox1
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:38
Joined
May 21, 2018
Messages
8,463
could also be that there is no value in form1, textbox1
Untested, but I think this will hopefully solve that case
Code:
if isnumeric(split(me.openargs,":")(0)) then me.textbox5= (cdbl(split(openargs,":")(0))) ' check you passed a number
if isnumeric(split(me.openargs,":")(1)) then Me.textbox6 =(cdbl(split(openargs,":")(1)))
 

Micron

AWF VIP
Local time
Today, 11:38
Joined
Oct 20, 2018
Messages
3,476
cross posted

adjudante please read https://www.excelguru.ca/content.php?184
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:38
Joined
Feb 19, 2013
Messages
16,553
bit cheeky, not even acknowledging it is not their own work - so I'm outta here, let the other forum take it up
 

Micron

AWF VIP
Local time
Today, 11:38
Joined
Oct 20, 2018
Messages
3,476
bit cheeky, not even acknowledging it is not their own work - so I'm outta here, let the other forum take it up

This is why I have a larger ignore list than (probably) most. If the OP acknowledges the transgression, then NP. If not, another one's on the list. I figure that I have better things to do than spend my time on those who don't care or don't understand.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:38
Joined
May 7, 2009
Messages
19,169
before anything, edit Form2 and add a Public function:
Code:
Public Function get_global(byval idx as integer) as single
get_global = 0
if idx = 1 then
    get_global = gbl_var1
elseif idx = 2
    get_global = gbl_var2
end if
end function

set the ControlSource of Textbox5 (form2) to:
Code:
=get_global(1)
likewise with textbox6 (form2):
Code:
=get_global(2)

1. in Module1 (module):
Code:
Global gbl_var1 as single
Global gbl_var2 as single
2. in form1 (click event of a button to open form2)
Code:
private sub button1_click()

gbl_var1 = val(me.textbox1 & "")
gbl_var2 = val(me.textbox2 & "")

if syscmd(acSysCmdGetObjectState, acForm, "Form2") > 0 Then
    docmd.close acForm, "Form2"
end if
docmd.openform "Form2"

docmd.close acForm, me.name
 

Users who are viewing this thread

Top Bottom