Synchronize subform on value in primary form

tstuve

New Member
Joined
Apr 29, 2002
Messages
19
Hi.

I'm a rookie to Access coding and have what is probably a simple problem for you all. I have a subform that I need to synchronize with its primary form on a field in that form. Here's the code:

Private Sub Command50_Click()
On Error GoTo Err_Command50_Click

Dim stDocName As String
Dim stLinkCriteria As Integer

stLinkCriteria = [ContactID]

stDocName = "Names"
DoCmd.OpenForm stDocName, , , [ContactID] = Me.ContactID

Exit_Command50_Click:
Exit Sub

Err_Command50_Click:
MsgBox Err.Description
Resume Exit_Command50_Click

End Sub

When I invoke the form load, I get all the contact names, and only want those pertinent to the company I'm currently working with. Thanks for your help as always.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If the set the Record Source for the subquery to a query where you have a statement in the where field that says:

WHERE ContactID=[FORMS].[enter form name here].[enter control name here]

Then add to your Command50_click [ form name].requery

Hope this helped!

-gator
 
Upvote 0
Not sure if I completely understood, here's the code after I modified. Still doesn't work right.


Private Sub Command50_Click()
On Error GoTo Err_Command50_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Names"
DoCmd.OpenForm stDocName, , , "'Contact ID' = Forms!form_contacts!contactid"
Form_Contacts.Requery


Exit_Command50_Click:
Exit Sub

Err_Command50_Click:
MsgBox Err.Description
Resume Exit_Command50_Click

End Sub
 
Upvote 0
Are you just trying to display a recordset where the subform's foreign key is equal to the primary key on the main form? If this is the case, you don't even need VBA. Just go to the subform's properties and link the foreign key Child field to the primary key of the Parent field. I don't know if this simple answer covers what you're trying to do or not.
 
Upvote 0
This sounds like it may work, but can you please educate the ignorant (i.e. ME)? How do you do this?
 
Upvote 0
What the Hell? I posted back yesterday, but now my post is gone. Oh well, anyway, just click on the subform, click on properties in the Toolbar, and set its Link Child and Link Master properties to the subform's foreign key and the main form's primary key, respectively. Post back and let us know if it did/didn't work.
 
Upvote 0

Forum statistics

Threads
1,223,533
Messages
6,172,883
Members
452,486
Latest member
standw01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top