Passing values from one form to another (or how to use OpenArgs?)

  • Thread starter Thread starter Alex via AccessMonster.com
  • Start date Start date
A

Alex via AccessMonster.com

Hi everyone. Maybe you guys can help me, here is the problem:
Form1 has a checkbox, when I check it another form pops up (say Form2).
Form1 has a control number(say 29), i need that control number be displayed
in box of a popping up form2.
But not only that, when I fill in Form2, there are two boxes I need to pass
values back to form1 once its saved. I've been doing a search on forums and
google, so far I am unable to understand the concept of OpenArgs. If anyone
could give me a code or something to look at or modify
I would be very grateful
Thanks
 
Hi everyone. Maybe you guys can help me, here is the problem:
Form1 has a checkbox, when I check it another form pops up (say Form2).
Form1 has a control number(say 29), i need that control number be displayed
in box of a popping up form2.
But not only that, when I fill in Form2, there are two boxes I need to pass
values back to form1 once its saved. I've been doing a search on forums and
google, so far I am unable to understand the concept of OpenArgs. If anyone
could give me a code or something to look at or modify
I would be very grateful
Thanks

You can pass an OpenArgs value to a form when you open it by code
using the last argument of the OpenForm method. The value passed is
always as a String.
So, if a control on your form contains the value you wish to send to
the other form, use:

DoCmd.OpenForm "Form2", , , , , , Me!ControlName

To then do something with the value in Form2, use Form2's Load event
to read the argument and take some action with it:

If Not IsNull(Me.OpenArgs ) Then
Me!ControlName = Me.OpenArgs
End If

To pass some values back to Form1 (as long as Form1 is open) use the
following syntax:
forms!Form1!ControlName = Me![ControlName]

Change [ControlName] to whatever the actual names of the controls are.
 
Wow, thanks Fred, it works. At least the first part, for the passing values
back- where do you put the code? on close event of a form or something
else, I have a code to promt user to save or not, so if its not saved then
the values shouldn't pass. Its kinda comlicated, but the other problem is
that I got 1st Name and Last Name to pass value to one text box on Form1,
which means I have to unite both 1st Name and Last Name. Saw the code on
how to do it vice versa, ie Name into 1st Name and Last Name
Thanks for replying and helping a noob like me. Saved me many hours of
search :)
 
Nevermind the previous post, I've figured it out.
Using the code
Forms!CommentCard!actioned_by = Me![employee_first_name] & Me!
[employee_last_name]
it passes the values, but there is no spacing between them, how can I
insert couple of spaces? in form1 txtbox it look like this "FrankSenatra"
Plz help
 
Just concatenate a string containing your space(s) between the two fields,
rather than simply concatenating the two fields directly:

Forms!CommentCard!actioned_by = Me![employee_first_name] & " as many
spaces as you want " & Me![employee_last_name]

Swap the order and include a comma in your string and you can get something
like "Sinatra, Frank", thus:
... Me![employee_last_name] & ", " & Me![employee_first_name]


HTH,

Rob
 
Back
Top