DoCmd.OpenForm criteria question

G

grep

I've got a form frmCompanies, with a subform sfrmCompContacts. The
subform shows all the contacts associated with a company. There's also a
form for Contacts (frmContacts).

I'd like to be able to double-click on the records in sfrmCompContacts
and have that contact's record open in frmContacts.

The problem is passing the link criteria. Here's what I'm trying:

dim stDocName, stLinkCriteria as string

stDocName = "frmContacts"
stLinkCriteria = "ContactID = Me.ContactID"

DoCmd.OpenForm frmContacts, , , stLinkCriteria

It doesn't work. It comes up with a box asking for the parameter for
Me.ContactID.

What am I doing wrong?

grep
 
G

grep

Yeah - that was it. Thanks!

Just out of curiousity, what it ContactID *were* a text value?

grep
 
R

Roger Carlson

Then it would be:

stLinkCriteria = "ContactID = '" & Me.ContactID & "'"

or

stLinkCriteria = "ContactID = """ & Me.ContactID & """"

or

stLinkCriteria = "ContactID = " & Chr(13) & Me.ContactID & Chr(13)

for a good explanation of the why behind this, go here:
http://rogersaccesslibrary.com/knowledge.html
and look for this link: BuildingAStringExpression.zip

--
--Roger Carlson
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
M

Marshall Barton

Roger said:
stLinkCriteria = "ContactID = " & Chr(13) & Me.ContactID & Chr(13)

Shouldn't that be:
. . . "ContactID = " & Chr(34) & Me.ContactID & Chr(34)
 

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