A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Filtering Multiple Values



 
 
Thread Tools Display Modes
  #21  
Old October 6th, 2008, 02:43 PM posted to microsoft.public.access.forms
Melissa
external usenet poster
 
Posts: 409
Default Filtering Multiple Values

Same thing.

It seems to have a problem with this code:

Me.Filter = varFilter

When I go into the debug window this is the code that is highlighted.
--
Melissa


"AccessVandal via AccessMonster.com" wrote:

Your original string was..

"([CSR] Like " '*" & Me.txtFilterCSR & "*')"

try to insert one ampersand like..

"([CSR] Like " & "'*" & Me.txtFilterCSR & "*')"

look at the single quote and double quotes.

Melissa wrote:
I removed the parenthesis but it gives me the same message. Sometimes it
comes up with this error:

Syntax error (missing operator) in query expression ' AND ([CSR] = 'smit'

and sometimes it comes up with this one:

You can't assign a value to this object

If Not IsNull(Me.txtFilterCSR) Then
varFilter = (varFilter + " AND ") _
& "[CSR] = '" & Me.txtFilterCSR & "'"
End If


The plus should work, if it doesn't, change it to an ampersand.
If Not IsNull(Me.txtFilterCSR) Then
varFilter = (varFilter & " AND ") _
& "[CSR] = '" & Me.txtFilterCSR & "'"
End If

--
Please Rate the posting if helps you

Message posted via http://www.accessmonster.com


  #22  
Old October 7th, 2008, 01:53 AM posted to microsoft.public.access.forms
AccessVandal via AccessMonster.com
external usenet poster
 
Posts: 461
Default Filtering Multiple Values

Key in this Debug.Print and look at your SQL string in the immediate window,
copy and paste the string to show us the results. Is the syntax correct?

If Not IsNull(Me.txtFilterCSR) Then
Debug.Print varFilter ' one before and....
varFilter = varFilter & " AND " _
& "[CSR] = '" & Me.txtFilterCSR & "'"
Debug.Print varFilter ' one after to view your strings
End If

Melissa wrote:
Same thing.

It seems to have a problem with this code:

Me.Filter = varFilter

When I go into the debug window this is the code that is highlighted.


--
Please Rate the posting if helps you

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200810/1

  #23  
Old October 7th, 2008, 02:46 PM posted to microsoft.public.access.forms
Melissa
external usenet poster
 
Posts: 409
Default Filtering Multiple Values

Here's where it takes me to in the SQL code when I go to the debug window

Me.Filter = varFilter
Me.FilterOn = True
Else
'show all records -- no filters specified
Me.FilterOn = False
End If

Me.Requery




--
Melissa


"AccessVandal via AccessMonster.com" wrote:

Key in this Debug.Print and look at your SQL string in the immediate window,
copy and paste the string to show us the results. Is the syntax correct?

If Not IsNull(Me.txtFilterCSR) Then
Debug.Print varFilter ' one before and....
varFilter = varFilter & " AND " _
& "[CSR] = '" & Me.txtFilterCSR & "'"
Debug.Print varFilter ' one after to view your strings
End If

Melissa wrote:
Same thing.

It seems to have a problem with this code:

Me.Filter = varFilter

When I go into the debug window this is the code that is highlighted.


--
Please Rate the posting if helps you

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200810/1


  #24  
Old October 8th, 2008, 05:05 AM posted to microsoft.public.access.forms
AccessVandal via AccessMonster.com
external usenet poster
 
Posts: 461
Default Filtering Multiple Values

But what is the filter string? Is the syntax correct? Post the filtered
string here for us to see.

Melissa wrote:
Here's where it takes me to in the SQL code when I go to the debug window

Me.Filter = varFilter
Me.FilterOn = True
Else
'show all records -- no filters specified
Me.FilterOn = False
End If

Me.Requery


--
Please Rate the posting if helps you

Message posted via http://www.accessmonster.com

  #25  
Old October 8th, 2008, 07:18 PM posted to microsoft.public.access.forms
Melissa
external usenet poster
 
Posts: 409
Default Filtering Multiple Values

My apologies... I am not too familiar with SQL terminology. I am learning
more and more as I read through these posts but any extra explanation you can
provide to me would be much appreciated.

Here is the filter string. I have several criteria setup to search from. But
for the purposes of this post, I am only including one of each type.
__________________________________________________ _____________________

Private Sub cmdFilter_Click()

Dim varFilter As Variant

'if the first control for ShipTo is filled out
If Not IsNull(Me.txtFilterShipTo) Then

'if it has multiple values
If InStr((Me.txtFilterShipTo), "~") 0 Then
varFilter = (varFilter + " AND ") _
& "('~' & [ShipTo] & '~' in '" & Me.txtFilterShipTo & "'"
Else

'only the one value in ShipTo filter is filled out
varFilter = (varFilter + " AND ") _
& "[ShipTo]= '" & Me.txtFilterShipTo & "'"

End If
End If


If Not IsNull(Me.txtFilterState) Then
Debug.Print varFilter ' one before and....
varFilter = varFilter & " AND " _
& "[State] = '" & Me.txtFilterState & "'"
Debug.Print varFilter ' one after to view your strings
End If

If Not IsNull(Me.txtFilterEmail) Then
varFilter = (varFilter + " AND ") _
& "([EmailAddress] Like '*" _
& Me.txtFilterEmail & "*')"
End If


If Not IsNull(varFilter) Then

'remove next line after everything works ok
Debug.Print varWhere
'press CTRL-G to look at Immediate (debug) window

Me.Filter = varFilter
Me.FilterOn = True
Else
'show all records -- no filters specified
Me.FilterOn = False
End If

Me.Requery

End Sub
__________________________________________________ _________________


Thanks,
Melissa


"AccessVandal via AccessMonster.com" wrote:

But what is the filter string? Is the syntax correct? Post the filtered
string here for us to see.

Melissa wrote:
Here's where it takes me to in the SQL code when I go to the debug window

Me.Filter = varFilter
Me.FilterOn = True
Else
'show all records -- no filters specified
Me.FilterOn = False
End If

Me.Requery


--
Please Rate the posting if helps you

Message posted via http://www.accessmonster.com


  #26  
Old October 9th, 2008, 04:36 AM posted to microsoft.public.access.forms
AccessVandal via AccessMonster.com
external usenet poster
 
Posts: 461
Default Filtering Multiple Values

To view the immediate window, in the VB editor, press Ctrl + G. Then copy and
paste the string here for us to see.

The code given by crystal. I’m not sure why she gave you that. In my opinion,
this will cause errors. Furthermore, it’s missing a parenthesis, quotes, and
incorrect use of “IN” clause. Not a complete code.

'if it has multiple values
If InStr((Me.txtFilterShipTo), "~") 0 Then
varFilter = (varFilter + " AND ") _
& "('~' & [ShipTo] & '~' in '" & Me.txtFilterShipTo & "'"

Else

'only the one value in ShipTo filter is filled out
varFilter = (varFilter + " AND ") _
& "[ShipTo]= '" & Me.txtFilterShipTo & "'"

End If

In the command button “cmdFilter”, what was or is the string value before the
click event? If there was nothing, why the “ AND “ ? this can cause error.
And if there is nothing in the beginning on the “varFilter” then, remove the
“ AND ”.

If you had multiple shipto addresses, you’ll need to open a recordset from
the filtered to correct company ID with multiple ShipTo addresses.

Is it possible not to filter the form with ship to?


Melissa wrote:
My apologies... I am not too familiar with SQL terminology. I am learning
more and more as I read through these posts but any extra explanation you can
provide to me would be much appreciated.

Here is the filter string. I have several criteria setup to search from. But
for the purposes of this post, I am only including one of each type.
_________________________________________________ ______________________

Private Sub cmdFilter_Click()

Dim varFilter As Variant

'if the first control for ShipTo is filled out
If Not IsNull(Me.txtFilterShipTo) Then

'if it has multiple values
If InStr((Me.txtFilterShipTo), "~") 0 Then
varFilter = (varFilter + " AND ") _
& "('~' & [ShipTo] & '~' in '" & Me.txtFilterShipTo & "'"
Else

'only the one value in ShipTo filter is filled out
varFilter = (varFilter + " AND ") _
& "[ShipTo]= '" & Me.txtFilterShipTo & "'"

End If
End If

If Not IsNull(Me.txtFilterState) Then
Debug.Print varFilter ' one before and....
varFilter = varFilter & " AND " _
& "[State] = '" & Me.txtFilterState & "'"
Debug.Print varFilter ' one after to view your strings
End If

If Not IsNull(Me.txtFilterEmail) Then
varFilter = (varFilter + " AND ") _
& "([EmailAddress] Like '*" _
& Me.txtFilterEmail & "*')"
End If

If Not IsNull(varFilter) Then

'remove next line after everything works ok
Debug.Print varWhere
'press CTRL-G to look at Immediate (debug) window

Me.Filter = varFilter
Me.FilterOn = True
Else
'show all records -- no filters specified
Me.FilterOn = False
End If

Me.Requery

End Sub
_________________________________________________ __________________

Thanks,
Melissa


--
Please Rate the posting if helps you

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200810/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.