I have an Access form that I am having trouble assigning a specific value to a field in that form. I have mostly used the wizards to create a lot of my forms, so I only have minimal experience with VBA coding. I will try to give the clearest picture on what I’m trying to do.
From “Form1” I added a button to open “Form2”. By using the wizards to create the “Form2”, when “Form2” opens, it has filtered the records based on the field “MemberID”. “Form1” is based on a “Table1” that has the field “MemberID” in it and “Form2” is based on “Table2” and it also has a field “MemberID” in it, so it can be used to link the two tables.
Once “Form2” opens from “Form1”, it displays the filtered records as it should. I want to add records to “Form2”. I created a button from the wizards to add a new record, but I want the button to also fill in the “MemberID” on “Form2” that is the same as the “MemberID” that was used to filter the data from “Form1”. Here is the only code that is on the Button on “Form2”. What code do I need to add so that the “MemberID” from “Form1” is placed in the “MemberID” field in the new record on “Form2”?
Private Sub AddBut_Click()
On Error GoTo Err_AddBut_Click
DoCmd.GoToRecord , , acNewRec
Exit_AddBut_Click:
Exit Sub
Err_AddBut_Click:
MsgBox Err.Description
Resume Exit_AddBut_Click
End Sub
From “Form1” I added a button to open “Form2”. By using the wizards to create the “Form2”, when “Form2” opens, it has filtered the records based on the field “MemberID”. “Form1” is based on a “Table1” that has the field “MemberID” in it and “Form2” is based on “Table2” and it also has a field “MemberID” in it, so it can be used to link the two tables.
Once “Form2” opens from “Form1”, it displays the filtered records as it should. I want to add records to “Form2”. I created a button from the wizards to add a new record, but I want the button to also fill in the “MemberID” on “Form2” that is the same as the “MemberID” that was used to filter the data from “Form1”. Here is the only code that is on the Button on “Form2”. What code do I need to add so that the “MemberID” from “Form1” is placed in the “MemberID” field in the new record on “Form2”?
Private Sub AddBut_Click()
On Error GoTo Err_AddBut_Click
DoCmd.GoToRecord , , acNewRec
Exit_AddBut_Click:
Exit Sub
Err_AddBut_Click:
MsgBox Err.Description
Resume Exit_AddBut_Click
End Sub