Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.OpenForm with criteria 1

Status
Not open for further replies.

zmsm18

Programmer
Sep 23, 2005
6
US
In Access mdb the following code would open form2 to the record that was selected via an click event on form1. It doesn't work in Project. Form2 opens, but goes to record 1, not the record selected on Form1. Am I missing a step in this? Any help is appreciated.

Private Sub HLTAG_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmINVEditALL"
stLinkCriteria = "[HLTAG] = '" & Me![HLTAG] & "'"

DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria

End Sub
 
I am having the same problem, did you find a solution?

Rock on!!
F
 
My form is working, but I still don't understand what is going on. It would work if form1 and form2 were pulling data from the same table, but not if from different tables, even though the key field was joined.

I finally recreated everything as an mdb instead of a Project then ran the "upsize wizard" and it works.

There is a difference in the code the Wizard produced. I'm not sure it that's it. I played around will many combinations of quotes and single quotes.

My earlier example:
stLinkCriteria = "[HLTAG] = '" & Me![HLTAG] & "'"

What is working now:
stLinkCriteria = "[HLTAG]=" & "'" & Me![HLTAG] & "'
 
I found the solution. Not sure why though.

Using your stlinkCriteria line and then opening the form twice, the first time just to open the form then open the form again with the criteria. It works

stLinkCriteria = "[ClientID]=" & "'" & Me![ClientID] & "'"
DoCmd.OpenForm stDocName
DoCmd.OpenForm stDocName, , , stLinkCriteria

I'm sure there is a better solution to it. But as they say....If it works; Don't "bleep" with it.

Rock on!
 
First, set your stLinkCriteria to the value on your open form.

stLinkCriteria = Me![HLTAG]


Then open the second form setting the field you want to match on Form2 to stLinkCriteria

DoCmd.OpenForm "FormName",,,"[Field on Form2] = " & stLinkCriteria

if its a number or

"[Field on Form2] = '" & stLinkCriteria & "'"

if it's a string value.

Paul




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top