Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto populate same field across different forms

Status
Not open for further replies.

EastCoast

Instructor
Apr 13, 2006
31
US
I have the same "ID" field in my 1st form and my 2nd form. When I click on a cmd button to go to the 2nd Form, the "ID" field on the 2nd form needs to automatically populate itself with the same "ID" that was in the 1st form.

Example: "ModelID" in the "Models" table (the 1st table) equals "10" so when I click on the cmd button, the "ModelID" field in the "ModelDetails" table (the 2nd table) should then be populated with "10").

I have tried changing the control source and row source of the 2nd form to equal the 1st form, but there is no data (no "10") in the "ModelID" field of the 2nd table to match up - I need the database to input that value for me.
 
have you tried
[forms]![secondform].[textbox]=[forms]![firstform].[textbox]
you may need to check if the second form is open.

Ian Mayor (UK)
Program Error
Programming is 1% coding, 50% error checking and 49% sweat as your application bombs out in front of the client.
 
Where do I type this? In the macro or in the field itself (which property of the field if it is the field?)? The 2nd form is supposed to open on the click so it is supposed to be opened and populate together.
 
Hi, EastCoast,

You could pass the ID with the OpenArgs argument of the DoCmd.OpenForm command, then write the value in the 2nd form's OnOpen event. Something like this:
Code:
DoCmd.OpenForm "ModelDetailsForm", , , , , , Me!ModelID
Then...
Code:
Private Sub Form_Open(Cancel As Integer)
Me!ModelID = Me.OpenArgs
End Sub
HTH,

Ken S.
 
Okay - I think I get the second line of code, but where do I put the first line (the "DoCmd.OpenForm...")? Is this attached to an event or just write it in VBA. (VBA is not my strong suit yet).
 
EastCoast,

The DoCmd.OpenForm is in the OnClick event of the command button.

Ken S.
 
Hi Eupher,
I put in the two lines just as you typed them. The first line in the OnClick event of the cmd button on the 1st Form and the second line of code in the OnOpen Event of the 2nd Form.

I got an error for the 2nd line of code. Here is the line it highlighted:
Me!ModelID = Me.OpenArgs
 
Okay, that was sample code. Be sure the names of the objects in the code correspond to the names in your forms, i.e.:
Code:
DoCmd.OpenForm "[red]The_Name_Of_Your_2nd_Form[/red]", , , , , , Me![red]Name_Of_Your_ModelID_Field_On_The_1st_Form[/red]
And...
Code:
Me![red]Name_Of_Your_ModelID_Field_On_The_2nd_Form[/red] = Me.OpenArgs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top