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  dBforums > PC based Database Applications > Microsoft Access > Simple Search Form Not So Simple

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-04-12, 13:11
seuta seuta is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Post Simple Search Form Not So Simple

Hello everyone. I am currently creating an Access 2007 database to keep track of technology assets for warranty, tagID#, and what location it is at.

Currently, I have just a single table called "Assets" with all the information. I created a form using just that table and put an unbound combobox in the header with a search button. This is to just search through the location of the fields currently in the table.

My code for the search button is:

Code:
Private Sub Command32_Click()
Me.Filter = "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
Me.FilterOn = True
End Sub
I click the button and absolutely nothing happens at all. All three test records are still present, nothing changes. I am completely unsure what is going on here.

Last edited by seuta; 01-04-12 at 17:23. Reason: Clarification and ytops.
Reply With Quote
  #2 (permalink)  
Old 01-05-12, 05:25
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Change your code to:
Code:
Private Sub Command32_Click()

    Debug.Print "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
    Stop
    Me.Filter = "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
    Me.FilterOn = True

End Sub
Then open the Debug window (Ctrl+G), re-open the form, perform a search and see what you get for a filter: it will be displayed in the Debug (immediate) window when the code stops.

The explanation could be that the first (leftmost) column of a combobox is Column(0).

Note: With this technique, you do not perform a search on the row set, you actually filter it (i.e. the rows that do not match the criteria are excluded from the form records).
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 01-05-12, 08:00
seuta seuta is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Quote:
Originally Posted by Sinndho View Post
Change your code to:
Code:
Private Sub Command32_Click()

    Debug.Print "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
    Stop
    Me.Filter = "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
    Me.FilterOn = True

End Sub
Then open the Debug window (Ctrl+G), re-open the form, perform a search and see what you get for a filter: it will be displayed in the Debug (immediate) window when the code stops.

The explanation could be that the first (leftmost) column of a combobox is Column(0).

Note: With this technique, you do not perform a search on the row set, you actually filter it (i.e. the rows that do not match the criteria are excluded from the form records).
Thank you very much, Sinndho. The values being in a different column was part of the problem. Your help was very useful and greatly appreciated, thank you!
Reply With Quote
  #4 (permalink)  
Old 01-05-12, 08:05
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
You're welcome!
__________________
Have a nice day!
Reply With Quote
Reply

Tags
form, search command, vba

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On