By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,475 Members | 2,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,475 IT Pros & Developers. It's quick & easy.

invoke a form with a button from another

P: 98
is there a way to make a button on a form open another form with the same record and carry over some of the data from the initial form?
Dec 15 '08 #1
Share this Question
Share on Google+
8 Replies


beacon
100+
P: 579
@trixxnixon
Hi Trixx,

Let's take this one step at a time. To open a form with a command button add the following VBA code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOpenForm_Click()
  2.  
  3.    'Use the DoCmd to open the form, acNormal is the view the form is opened in
  4.    DoCmd.OpenForm "NextForm", acNormal
  5.  
  6. End Sub
  7.  
If you need to pass parameters, we need to figure out how much data you are trying to pass because there are different methods of doing so.

For instance, if you need to pass the value of one text box, you VBA would look like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOpenForm_Click()
  2.  
  3.    'Declare a variable to hold the value of the text box
  4.    Dim myVar
  5.  
  6.    'Set the value of the variable equal to the text box
  7.    myVar = txtAddress.Value
  8.  
  9.    'Now use the OpenForm method and use the variable in the_
  10.        OpenArgs section, which is the 5th comma after acNormal
  11.    DoCmd.OpenForm "NextForm", acNormal, , , , , myVar
  12.  
  13. End Sub
  14.  
Then on the form you are trying to open, I would create an invisible text box called myParameter and then enter the following VBA code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.    'Set the myParameter text box equal to OpenArgs
  4.    myParameter.Value = me.OpenArgs
  5.  
  6.    'Then you can set the desired text box equal to myParameter
  7.    txtSecondAddress.value = myParameter.Value
  8. End Sub
  9.  
If you need to pass multiple pieces of data, then you have to put each parameter in OpenArgs, separate each with an ampersand (&) and a semicolon in quotations. Then, once you've passed the OpenArgs, you have to separate each piece of data with the Split() function.

I'm not going to rewrite it because missingLinq has already done it. Here's a link to the page that helped me out tremendously and changed the way I look at forms. http://bytes.com/topic/access/answer...ue-form1-form2

Hope this helps

- beacon
Dec 15 '08 #2

P: 98
@beacon


i only need to transfer the data from one text box from another, this should help. i am going to try it right now.

thank you for such a quick responce.
Dec 15 '08 #3

beacon
100+
P: 579
Let me know how it works out.

If you get this down, you can move on to the step I just recently got to work...reading a parameter from user input on an initial form and then passing it to each subsequent form (including the Switchboard) to ensure that the user only selects data that pertains to them.

This just involves putting a myParameter invisible text box on each page that should receive the parameter and making sure that the parameter is passed in OpenArgs.

So, let's say I open the db and the form asks me to select myself from the list. I choose my name, select submit, and I'm taken to the Switchboard and a text box says "Welcome back beacon!" Then I choose to open another form, and in the name field it already has beacon. Using it with DLookup, I could potentially fill in other information that relates to me as long as the parameter is passed successfully.

Anyway, just some things to try if you get your initial question to work properly.

- beacon
Dec 15 '08 #4

P: 98
@beacon


oh no, i got it to work with no problem, i still dont quite understand the open argument, but i know how to use the basic principle.

so now that i have the correct field populating with the parent forms data,
i want a subform to take this tracking number, and plug it into a query and display all the records relating to that specific number.

i guess what i am asking is, would this be possible? and would it be the best design for this type of need?
Dec 15 '08 #5

beacon
100+
P: 579
@trixxnixon
Open Argument is something that attaches to the command as it performs its action. Not sure that's the best technical explanation for it, but it works for me. Here's a corny analogy to help explain OpenArgs:

When you run the command, think of it as a pizza being delivered. OpenArgs are the side items that come with the pizza...napkins, parmesan cheese, red pepper, etc. But the pizza delivery place you ordered from doesn't just give you the side items all the time, you have to specify what you want. As long as you specify it, the items will come with your pizza guaranteed (take that Pizza Hut!).

When the command has run, in your case when it has opened the second form, that's like you accepting the pizza at your front door, as well as the side items. Once you've got the side items, it's up to you how you put them to use. Maybe you put parmesan on pepperoni pizza or red pepper on anchovi (haha) pizza...it's all up to you. This is when you set your text box equal to the me.openargs.

so now that i have the correct field populating with the parent forms data,
i want a subform to take this tracking number, and plug it into a query and display all the records relating to that specific number.

i guess what i am asking is, would this be possible? and would it be the best design for this type of need?
I'm not sure I understand the second part of your question because I don't have a ton of experience with subforms. Is the tracking number the parameter that you passed through OpenArgs?

When you open the second form, does the query you're talking about automatically run with all data and now you want to limit the search to just those that match the tracking number?
Dec 15 '08 #6

FishVal
Expert 2.5K+
P: 2,653
Here you may find some additional indormation on this topic.

Regards,
Fish
Dec 15 '08 #7

P: 98
@beacon

right after i posted this i was able to get it working,

thanks for your help by the way, i hope one day i can return the favor.
Dec 16 '08 #8

P: 98
@FishVal
you really know your stuff. how long have you been doing this?
Dec 16 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.