Linking forms/tables

B

Brad

Hi

When I change from my company screen to the contact screen, i have managed
to get it to opne the contact form with the contact details from the previos
screen.

This is in my code to do this:

stLinkCriteria = "[ContactID]=" & Me![ContactID]
stDocName = "Contacts"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

However, when I try and do it the other way around with this:

stLinkCriteria = "[CompaniesID]=" & Me![CompanyID]
stDocName = "Company"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Its coming up with a compile error.

However I have tried to put it in so that I can do the same from contact to
company (i.e. when I am on a contacts details, I can click there company name
and it goes to the company screen showing there details). The company index
field on the contacts table is called 'CompanyID' and the company index field
on the company table is called 'CompaniesID'.

Anyone know what I am doing wrong?
Just to clarify, what I want to do is:

Open Contact form, choose contact. Click on contact company and then this
opens the Company form, showing details of that particular company. At the
moment the company form opens, but it just shows the first record.

Appreciate your help with this, I am very new to Access.

Thanks

Brad
 
R

Rick Brandt

Brad said:
Hi

When I change from my company screen to the contact screen, i have
managed to get it to opne the contact form with the contact details
from the previos screen.

This is in my code to do this:

stLinkCriteria = "[ContactID]=" & Me![ContactID]
stDocName = "Contacts"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

However, when I try and do it the other way around with this:

stLinkCriteria = "[CompaniesID]=" & Me![CompanyID]
stDocName = "Company"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Its coming up with a compile error.

Compile errors should tell you the line of code specifically it doesn't
like. What is the exact error you are getting and on what line?
 
B

Brad

Hi

It is on:

stLinkCriteria = "[CompaniesID]=" & Me![CompanyID]

And says 'variable not defined'.

Thanks

Brad

Rick Brandt said:
Brad said:
Hi

When I change from my company screen to the contact screen, i have
managed to get it to opne the contact form with the contact details
from the previos screen.

This is in my code to do this:

stLinkCriteria = "[ContactID]=" & Me![ContactID]
stDocName = "Contacts"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

However, when I try and do it the other way around with this:

stLinkCriteria = "[CompaniesID]=" & Me![CompanyID]
stDocName = "Company"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Its coming up with a compile error.

Compile errors should tell you the line of code specifically it doesn't
like. What is the exact error you are getting and on what line?
 
R

Rick Brandt

Brad said:
Hi

It is on:

stLinkCriteria = "[CompaniesID]=" & Me![CompanyID]

And says 'variable not defined'.

Do you have a line before that like...

Dim stLinkCriteria as String

(you should have)
 

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