what am I doing wrong?

cdoyle

Registered User.
Local time
Today, 10:41
Joined
Jun 9, 2004
Messages
383
Hi,
Trying to make the selection in a combo box on frm1 be the filter on frm2.

I found this example by searching the form, but it's not working for me

Option Compare Database

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "form_lastnametotal_exludeholidayform"

stLinkCriteria = "[Employee_Name]=" & Me!cboMyCombo
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub

I get an 'the openform action was canceled' error?

Any ideas?
The second form is based on a query

Thanks
 
The code looks fine so it is probably the data. Try this:
Code:
stLinkCriteria = "[Employee_Name]=" & Me!cboMyCombo
[COLOR="Red"]MsgBox "stLinkCriteria = [" & stLinkCriteria & "]"[/COLOR]
DoCmd.OpenForm stDocName, , , stLinkCriteria
You may need to specify Me!cboMyCombo.Column(n) to get the data you want. (n = 1 for the 2nd column)
 
Another example you can look at

This may be more work than what you are doing but I will post it anyhow
 

Attachments

RuralGuy said:
The code looks fine so it is probably the data. Try this:
Code:
stLinkCriteria = "[Employee_Name]=" & Me!cboMyCombo
[COLOR="Red"]MsgBox "stLinkCriteria = [" & stLinkCriteria & "]"[/COLOR]
DoCmd.OpenForm stDocName, , , stLinkCriteria
You may need to specify Me!cboMyCombo.Column(n) to get the data you want. (n = 1 for the 2nd column)

Hi,
I tried this, and it's still not working for some reason. Just get that error.
Is there anything I need to do within the query, or the second form?
 
It is a text field and needs to have quotes.
stLinkCriteria = "[Employee_Name]=" & Chr(34) & Me!cboMyCombo & Chr(34)
 
hmm,
still not working.

Now I get this error

'stlinkcriteria=[[Employee_Name]='71']

The number changes depending on what name I select.

but the second form at least opens now.
 
OK,
got it working!!

thanks for your help!
 
The bound column is probably an EmployeeID field. Try the second column.
stLinkCriteria = "[Employee_Name]=" & Chr(34) & Me!cboMyCombo.Column(1) & Chr(34)
 
Glad you got it working. What did you end up doing so others may benefit?
 
RuralGuy said:
The bound column is probably an EmployeeID field. Try the second column.
stLinkCriteria = "[Employee_Name]=" & Chr(34) & Me!cboMyCombo.Column(1) & Chr(34)

That's exactly what it was! I had it set to the wrong column, I changed it, and it worked!
 

Users who are viewing this thread

Back
Top Bottom