Adding query bound to text bozes on a form

B

Bob Quintal

I have the following command that works perfectly.

docmd.openform "MyForm1",,,"opponent in (" &
Me.opponentselected & ")"

I am now trying to add 2 more criteria to the filter when I
open the form. I can't quite get the code right.

(maingameformation.season)= Me.cboseason

(maingameformation.team)=Me.cboteam
try

"opponent in (" & Me.opponentselected & _
") AND maingameformation.season =" & Me.cboseason _
"maingameformation.team =""" & me.cboteam & """"

This assumes that the table field type for season is number and
for team is text.
 
G

Guest

I have the following command that works perfectly.

docmd.openform "MyForm1",,,"opponent in (" & Me.opponentselected & ")"

I am now trying to add 2 more criteria to the filter when I open the form. I
can't quite get the code right.

(maingameformation.season)= Me.cboseason

(maingameformation.team)=Me.cboteam
 
G

Guest

This works now with the 2 parameters.

DoCmd.OpenForm "reportfiltergameentryfrm", , , "opponent in (" &
Me.opponentselected & ") AND maingameformation.season = " & Me.cboseason

I am still having trouble with adding
(maingameformation.team)=Me.cboteam

[maingameformation.team] and [cboteam] are both text fields. only 1
possible variable. the result of [cboteam] does not have quotes around it, I
don't know if that matters?
 
D

Douglas J. Steele

Fipp said:
This works now with the 2 parameters.

DoCmd.OpenForm "reportfiltergameentryfrm", , , "opponent in (" &
Me.opponentselected & ") AND maingameformation.season = " & Me.cboseason

I am still having trouble with adding
(maingameformation.team)=Me.cboteam

[maingameformation.team] and [cboteam] are both text fields. only 1
possible variable. the result of [cboteam] does not have quotes around it,
I
don't know if that matters?

If it's a text field, you need quotes around the value being passed:

DoCmd.OpenForm "reportfiltergameentryfrm", , , _
"opponent in (" & Me.opponentselected & ") AND " & _
"maingameformation.season = " & Me.cboseason & _
"maingameformation.team = '" & Me.cboteam & "'"

Of course, it's unusual to include the table name in the condition like
that: you can only do that if you have two different fields named "season"
in the query (or two different fields named "team")
 
G

Guest

I first modified the query thus eliminating the need for the refrence to the
table.

I placed your code in (minus the table refrence) and I received the
following error message.

Run-time error '3075'

Syntax error (missin operator) in query expression 'opponent in ("Cal Poly")
AND season=2006team='San Jose State".


here is the information that was entered in my form.
on my form, [season]=2006
[opponent]="Cal Poly"
[team]=San Jose State

It looks as if there is a single quote mark right before the S on San jose
state in the error message? I am not sure if this could be it and if it is
how to fix it?
 
D

Douglas J. Steele

Sorry, partly my fault, partly yours.

I left out the AND (and the spaces around it): you missed the fact that I'd
put a single quote after as well.

DoCmd.OpenForm "reportfiltergameentryfrm", , , _
"opponent in (" & Me.opponentselected & ") AND " & _
"season = " & Me.cboseason & " AND " & _
"team = '" & Me.cboteam & "'"

Exagerated for clarity, that last line is:

"team = ' " & Me.cboteam & " ' "
 

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