filling fields on linked forms automatically

P

Polly

Hello,

I have two forms.

The first is [Company], fields: companyID (primary), CompanyName
Website.

The second is [Contact], fields: ContactID (primary), Company ID
Title, FirstName,Surname etc.


There is a command button on [Company] that links to the second form
[Contact].

What I would like, is when you open the [Contact] form from this link
the [CompanyID] field is automatically filled. (This is the field the
are linked together by)

Any help would be greatly appreciated (I'm not all that experience
with access, and can have problems with VBA - although I am gettin
better!)

Poll
 
N

Nikos Yannacopoulos

Polly,

You are not clear on what you want to do with the second form: open it for
new data entry, or just filter existing records on the CompanyID?
In the first case, the code should be something like:

cid = Me.CompanyID
DoCmd.OpenForm "Contact", acNormal, , , acFormAdd
Forms!Contact.CompanyID = cid

In the second case:
cid = Me.CompanyID
DoCmd.OpenForm "Contact", acNormal, , "[CompanyID] = " & cid
(if CompanyID is numeric, or)
cid = Me.CompanyID
DoCmd.OpenForm "Contact", acNormal, , "[CompanyID] = ' " & cid & " ' "
(if CompanyID is text).

In any case, make sure the names are spelled correctly.

HTH,
Nikos
 
P

Polly

Hi Nikos,

Apologies for not being clearer, I am indeed opening it for new dat
entry so this is great stuff.

Thanks very much for your help,

Poll
 

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