Full Version: How to connect forms?
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
jpalker
Hello,

I'm a new user to Access, & I have a question about some forms. Because I have so much different data to collect and enter into my database, I have different forms for different types of data instead of one big form that's unwieldy to use. I use the forms to enter data about my staff. So, for example, I have a basic information form where I enter things like addresses, phone numbers, etc. But then I have another form that I use to enter information about their positions once they're hired, for example.

This is the best system for us, but sometimes when we are entering data, we want to enter both types of data. I'm wondering if there is a way to "link" the two forms. I have a button control on the first form that opens the other form, but it would be awesome if clicking that button to go to the second form automatically brought me to the form with the same person's information automatically displayed instead of just the first record in the table.

Hopefully I've described what I'm looking for clearly, if anyone has any advice, it would be much appreciated. Thanks!

smile.gif Jess
Alan_G
Hi Jess

You can use the WHERE parameter of the OpenForm method to do that. Assuming you have a numerical StaffID and a textbox called something like txtStaffID on your calling form, in the Click event procedure of a command button put

CODE
Docmd.OpenForm "NameOfFormToOpen", , , "StaffID = " & Me.txtStaffID
jpalker
This makes sense, thanks for your help. One point to clarify--when you say to put the text box in the calling form, do you mean that the first form is the calling form (since it's calling the second)? Just want to make sure I understand so I put the code in the correct form's properties. smile.gif

Thanks!
jpalker
Never mind, I figured it out! Made perfect sense when I looked at it instead of just thought about it. Works like a charm, thanks so much, again!

smile.gif Jess
Alan_G
Hi

Yep, I meant the first form is the calling form wink.gif

The code itself goes in the VBA editor though, not one of the forms properties. If you put a new command button on the form, then look in the properties window under the Event tab you'll see a property called Click. If you then click on the three little elipses at the end of that line it will open the VBA editor window (choose Code Builder if you get offered a choice) with the cursor flashing at the correct place to enter the code
Alan_G
Hi

I guess we were typing at the same time - glad you got it working thumbup.gif
jpalker
Perfect, thanks!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.