Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to filter by form in VB6 like I would in an Access Form

Status
Not open for further replies.

MHagan

Technical User
Feb 6, 2002
8
US
Hi! I created a nice little form in access that will allow users to find records using the filter by form buttons.

However, I need to make this form available to users who do not have MS Access. Unfortunately, I don't have Microsoft Office Developer or this would be easy.

I created a form in VB6 based on the Access Database, and it will run. However, I don't know much about Visual Basic so I just used the wizard to create this application. The problem is I don't know how to add the buttons to filter the data, and everything I have researched looks too complicated.

Can you help me?
 
There may be a custom control or something else that I'm not aware of that would give you the Filter By Form function with a minimum of programming. Unless somebody else here knows of such a thing, I'd say you're going to have to program this one yourself. It's not that bad.
How are you connecting to the database? ADO? DAO? If you don't know, what Wizard did you use to create what you've got?
 
I used ADO. Also, I just used the Application Wizard and the Data Control Wizard.

 
I used the Data Form Wizard to make a quick form based on the Biblio.mdb database so my example will use the names that the Wizard assigned to my controls.
So, you've got an Adodc control on your form with other controls bound to it.. my Adodc control is called datPrimaryRS. The wizard gave me text boxes in which to show records but it doesn't really matter how you're showing them.
If I understand the Filter On Form function, you want to give your users a text box where they can type in what they're looking for. Paint a TextBox somewhere on your form. Also add a CommandButton. You might want to clear the TextBox's Text property so it doesn't say "Text1" before the user types anything into it. Double-click on the CommandButton - that should put you in the middle of the Command1_Click event in the code view. Put this code in that even procedure.

Private Sub Command1_Click()
datPrimaryRS.RecordSource = "SELECT YourFields FROM YourTable WHERE FieldToBeSearched Like '%" & Text1 & "%'"
datPrimaryRS.Refresh
End Sub


Replace datPrimaryRS with the name of your Adodc control. So, when the user clicks Command1, your program will modify the SQL statement that the Adodc control is using to pull records from the database.

Something that I find a little strange is that Access uses the asterisk for its "0 or more unknown characters" wildcard and yet when I used an asterisk I got no records. I tried a percent and it worked. I don't use ADO much. Maybe that's how it works.
 
Thank you so much for your response! I will try your suggestion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top