1,105,384 Community Members

vb 6.0 code for search buttons

Member Avatar
problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
1
 

hi. I am working on a project that requires a search button. it goes like this. the I will enter data on a text box. then the record that goes with it will display on the 3 textboxes. My problem is I don't know how to code a search buttons. please help.

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

What kind of database are you using, access, MySql etc?

Member Avatar
PoisonedHeart
Junior Poster in Training
60 posts since Jul 2009
Reputation Points: 4 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
0
 

Could you give us some sample data on what kind of data you were searching?

-> for example: like typing the Customer ID on a textbox, then perform search and display the customer info. such as last name, first name and middle name on these three texboxes...(Are these is what you are trying to do?)


regarding the coding of your search button, if it has a back-end database, then use the SELECT statement to query results....within your recordset object...

SELECT CustomerID, lastname, firstname FROM tblCustomers WHERE lastname LIKE 'V%'

-> this select statement will show result those customers that have a last name starting with the "V" letter.

Member Avatar
problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

@andreret I'm sorry I forgot. it's ms access 2003


@poisoned heart the data that will be typed on the text box is a name, then the it would display some selected information of the name that was searched.

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Your select statement would be -

SELECT * FROM MyTableName WHERE TheName LIKE " & "'" & "Prob%" & "'"

This will return all names in the database that has prob in itself.

Have a look at the following link -

http://www.techonthenet.com/sql/like.php

Member Avatar
problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

@andre are you sure this will work in vb6? because when I use this code there is always an error even when I play around the code.

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Do the following -

Option Explicit

Private Sub cmdSearch_Click()

'Declare connection and recordset
Dim cnSearch As ADODB.Connection
Dim rsSearch As ADODB.Recordset

'Create a new instance of connection and recordset
Set cnSearch = New ADODB.Connection
Set rsSearch = New ADODB.Recordset

'Open connection
cnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\MySearch.MDB;Persist Security Info=False"
  
'Open recordset
Dim strSql As String

strSql = "SELECT * FROM MySearch WHERE Name LIKE " & "'" & "And%" & "'"

rsSearch.Open strSql, cnSearch, adOpenStatic, adLockOptimistic

'See if any records exist. If not exit sub and close connection and
'recordset. If yes, display data in text boxes

If rsSearch.BOF = True Or rsSearch.EOF = True Then
    MsgBox "No records exist"
    
    rsSearch.Close
    cnSearch.Close
    
    Exit Sub
        Else
    Text1.Text = rsSearch!Name
    Text2.Text = rsSearch!Surname
    
    rsSearch.Close
    cnSearch.Close
End If
End Sub

This works 100% within VB6 AND Access.

Member Avatar
problematic:)
Light Poster
31 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

OK thank you! I got it! it works perfectly fine!!!!!!!! THANKS a LOT!!!!!!!!!!!!!

Question Answered as of 3 Years Ago by AndreRet and PoisonedHeart
Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Only a pleasure. Happy coding.

Member Avatar
pgalivar11
Newbie Poster
2 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i really like to get information in your web site...it really helps..thanks...im philip,new member..

Member Avatar
jennylynB
Newbie Poster
2 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi.....im jennylyn,i would like to ask you guys if what would be a code for SEARCH in database....like if we would find the name or gender????pls post a code guys....need it in our activity!!!!!!thanks..............:)

Member Avatar
jennylynB
Newbie Poster
2 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi.....im jennylyn,i would like to ask you guys if what would be a code for SEARCH in database....like if we would find the name or gender????pls post a code guys....need it in our activity!!!!!!thanks..............

Member Avatar
Jx_Man
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]
Featured
 
0
 

hi.....im jennylyn,i would like to ask you guys if what would be a code for SEARCH in database....like if we would find the name or gender????pls post a code guys....need it in our activity!!!!!!thanks..............

Post your own thread here. Also post the code you working on.

sai.pawar.p
Newbie Poster
1 post since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

Quoted Text Here

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article