Linking forms

U

ugogirl65

Very new to Access and I am having trouble getting my forms right.



Table1

companyId

company.....

Table2

contactId

Name.....





From the company form I want to be able to open the contact form and
either view or add data. I made a button using the wizard to open
Form2 which works fine. Form 2 starts out companyID and then Contact
Id. The Contactid works fine, but the CompanyId is never filed in so I
can't save the contact record. I know this is really simple but it's
making me nuts



Thanks
 
S

Steve Schapel

ugogirl,

If you want to add new contacts in Table2 which are related to the
company which is current on the Table1 form, you need to tell Access
specifically to use this relationship. This assumes that Table2 also
has a companyId field, which you didn't state, but I guess must be so
since you have it on the 2nd form.

One way to do this (recommended!) is to put the Table2 form onto the
Table1 Form as a subform. Set the LinkChildFields and
LinkMasterFields properties of the subform to CompanyID, and contacts
entered will then automatically have the correct companyId entered.

Otherwise, you might need to put some vba code somewhere to set the
value of the companyId on the 2nd form. For example, the OnClick
procedure on the button on the first from that opens the second form,
might look like this...
Private Sub YourButton_Click()
DoCmd.OpenForm "Form2"
DoCmd.GoToRecord , , acNewRec
Forms!Form2!companyId = Me.companyId
End Sub

- Steve Schapel, Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top