filling fields on linked forms automatically

  • Thread starter Thread starter Polly
  • Start date Start date
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
 
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
 
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
 
Back
Top