Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 18th, 2004, 10:32 AM
davidlloyd365 davidlloyd365 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 4 davidlloyd365 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Filtering in forms

I am compiling what seems to be a very simple database, but having not used access for a few years I am really struggling.The database contains only 1 table. Using only one form, all I want to do is be able to choose the field to search from a combo box, type the search criteria into a text box. Then hit a command button which will bring up all records which match the search criteria. After visiting my local library and taking out a stack of books I am still unable to do this and am wallowing in self pity.The following is the best piece of code that I have produced but still fails to work. Has anyone got any ideas?

Private Sub Command21_Click()
Dim strSearchField As String
Dim strSearchCriteria As String 'place search cirteria into strings

txtField.SetFocus 'combobox
strSearchField = txtField.Text

txtCriteria.SetFocus 'text box
strSearchCriteria = txtCriteria.Text

'apply the filter to the data

Me.Filter = "(strsearchfield) = (strsearchcriteria) & *"
Me.FilterOn = True

End Sub


Ideally I would like to include a wild card after "strsearchfield" to allow a user to type "A" and then bring up all records beginning in A, I have no idea if this is possible. Apologies if this code is laughable but it is the best I can do.

Reply With Quote
  #2  
Old August 19th, 2004, 09:19 PM
ineuw ineuw is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 82 ineuw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 28 sec
Reputation Power: 5
You have a bit of incoherent spaghetti in your code. Do you wish to filter the combo box or the record? These are two different things. Also, what is "& amp" at the end of your filter? Restate your post in clearer terms as to what you wish to do and then we'll alleviate your suffering . . . . until then, happy wallowing.

Reply With Quote
  #3  
Old August 20th, 2004, 04:22 AM
davidlloyd365 davidlloyd365 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 4 davidlloyd365 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Apologies, here is the corrected code



txtCriteria.SetFocus

If txtCriteria.Text = "" Then

MsgBox "No criteria selected, all records displayed.", vbOKOnly
DoCmd.ShowAllRecords


Else

strSearchField = Me.txtField.Value
strSearchCriteria = txtCriteria.Value


'apply the filter to the data

Form.Filter = strSearchField & " Like '" & strSearchCriteria & "*'"
Me.FilterOn = True
Me.Requery 'this line may be superfluous


End If







strSearchField is from a combo box containing all field headings with selection limited to the list.

The user can select a field to search then type the criteria they which they to search for into "txtCriteria"

For fields containing only characters the filter works fine however the following error message appears for

the remaining fields that contain numbers.



"Syntax Error (missing operator) In Query Expression: Form.Filter = strSearchField & " Like '" & strSearchCriteria & "*'"



(that’s not quite the run time error but is hopefully easier to understand)



Has anyone got any suggestions?

Reply With Quote
  #4  
Old August 20th, 2004, 06:21 AM
ineuw ineuw is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 82 ineuw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 28 sec
Reputation Power: 5
There should be no difference when filtering for character or number strings since the form filter syntax is nearly identical to an SQL WHERE criteria syntax. Bracketing is important and you are referring to a field object which should be enclosed with [] so try the following:
"((([" & strSearchField & "]) Like " & strSearchCriteria & "*))". When in doubt, you can first test your filter construct with a query. You can also evaluate the field type (date, number, text or boolean) and the search string before constructing the filter.


Reply With Quote
  #5  
Old August 29th, 2004, 05:03 PM
Revrick Revrick is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 Revrick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello. I am having the same exact error as mentioned above, and none of the suggestions posted help.

Maybe someone has come across this before, and would be willing to share some light on the subject.

I have a form and would like the text FNAME = <inputted text>*
Alternativley FNAME = LIKE <inputted text>*

Anything that will show me all the results beginning with <inputted text>

This produces no errors and give me FNAME = <inputted text>
strFilter = "FNAME = '" & TFirst.Value & "'"
Me.SubFoundCustomers.Form.Filter = strFilter

If i manually go into the subform and change its forms filter to FNAME = <inputted text>* and then create a button to turn the FilterOn property to true, i get the correct results. But when i concat an *(in any logically place) i get the following error:

Run-time error '3075':
Syntax error (missing operator) in query expression 'FNAME = 't'*'.

I need help with this. Does anyone have any suggestions?

NaTe

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Filtering in forms


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT