Filter form with 2 combo boxes error

G

Guest

Hi everyone,

I have a little problem filtering two fields in a continuous form :(


Private Sub filtro_Click()
Dim ftrcand As String
Dim ftrseccao As String

ftrcand = "[desig_candidatura_a] = '" & Me!cand_a & "'"
ftrseccao = "[gt design] = '" & Me!gt & "'"

If ((Not IsNull(Me.cand_a)) And (((Not IsNull(Me.gt)) ))) Then
Me.Filter = "[desig_candidatura_a] = '" & Me!cand_a & "'" and "[gt design] =
'" & Me!gt & "'"
Me.FilterOn = True
End If

Both fields are in text format, and if i try to filter only one option there
is no problem

--
Thanks,

Sorry if my english isn''t correct, but I''m from Potugal ;)

Emanuel Violante Galeano
 
B

Brendan Reynolds

Emanuel Violante said:
Hi everyone,

I have a little problem filtering two fields in a continuous form :(


Private Sub filtro_Click()
Dim ftrcand As String
Dim ftrseccao As String

ftrcand = "[desig_candidatura_a] = '" & Me!cand_a & "'"
ftrseccao = "[gt design] = '" & Me!gt & "'"

If ((Not IsNull(Me.cand_a)) And (((Not IsNull(Me.gt)) ))) Then
Me.Filter = "[desig_candidatura_a] = '" & Me!cand_a & "'" and "[gt design]
=
'" & Me!gt & "'"
Me.FilterOn = True
End If

Both fields are in text format, and if i try to filter only one option
there
is no problem


The quotes are not quite right, the "and" is falling outside the quotes,
causing it to be interpreted as part of the VBA code instead of as part of
the SQL statement. Try something like this ...

Me.Filter = "[desig_candidatura_a] = '" & Me!cand_a & "' And [gt design] =
'" & Me!gt & "'"
 

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