| | |
Searching for records contained in access from VB
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2005
Posts: 5
Reputation:
Solved Threads: 0
Hi there,
i m not a very advanced programmer so i have now come up against a brick wall. i need to use a VB code preferably on a command button, whereby the user enters a keyword into a text box, clicks the 'Search' command button, and then a procedure looks up the information from the tables contained in the relational access database and displays it in text boxes on a VB form.
I am using the ADODC VB function.
Any help will be appreciated i am DESPERATE!! thanx alot :-)
i m not a very advanced programmer so i have now come up against a brick wall. i need to use a VB code preferably on a command button, whereby the user enters a keyword into a text box, clicks the 'Search' command button, and then a procedure looks up the information from the tables contained in the relational access database and displays it in text boxes on a VB form.
I am using the ADODC VB function.
Any help will be appreciated i am DESPERATE!! thanx alot :-)
I'm not sure how similar ADODC is to DAO, but this is what I've used in the command buttons click event
Table, txtInputBox are my substitutions, I think you'll understand how you apply to your table and text box.
This it's just a matter of cycling through the records returned by Rs and populate whatever text, list or combobox or whatever.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim Sql as String Sql = "SELECT * FROM Table WHERE Str = '" & txtInputBox & "'" Set Rs = Db.OpenRecordset (Sql)
Table, txtInputBox are my substitutions, I think you'll understand how you apply to your table and text box.
This it's just a matter of cycling through the records returned by Rs and populate whatever text, list or combobox or whatever.
•
•
•
•
Originally Posted by Tight_Coder_Ex
I'm not sure how similar ADODC is to DAO, but this is what I've used in the command buttons click event
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim Sql as String Sql = "SELECT * FROM Table WHERE Str = '" & txtInputBox & "'" Set Rs = Db.OpenRecordset (Sql)
Table, txtInputBox are my substitutions, I think you'll understand how you apply to your table and text box.
This it's just a matter of cycling through the records returned by Rs and populate whatever text, list or combobox or whatever.
do you have anything else?
Try taking a look at my ADO tutorial http://www.timesheetsmts.com/adotutorial.htm
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
Join Date: Apr 2005
Posts: 8
Reputation:
Solved Threads: 0
This is a very simple question, and I don't know y everyone tries to teach lostprophet in his manner.
You just right this code and assume that ur database name is "test.mdb".And u have table named "t1" having 2 fields "invoice" & "Name"
You just right this code and assume that ur database name is "test.mdb".And u have table named "t1" having 2 fields "invoice" & "Name"
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command1_Click() Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Persist Security Info=False" Adodc1.CommandType = adCmdText Adodc1.RecordSource = "select name from t1 where invoice like '" & Textbox1.Text & "'" Adodc1.Refresh If Adodc1.Recordset.RecordCount > 0 Then Textbox1.Text=Adodc1.Recordset.Fields(0) End if End Sub
My suggestion is to use DAO 3.6 Library..it's easier to use than ADO..
Your solution would be like:
------------------------------------------------------
Private Sub CmdSearch_Click()
Dim ws as Dao.Workspaces
Dim db as Dao.database
Dim rs As RecordSet
Dim mysql As string
Dim search as String
On Error Resume Next
set ws = dbengine.workspaces
set db = ws(0).openDatabase(app.path & "\test.mdb".False.False)
search = Inputbox("Enter something to search: ")
mysql = "SELECT * FROM table_name WHERE field_u_want like '*" & search & "*'"
Set rs = db.OpenRecordSet(mysql)
If rs.recordcount = 0 Then Msgbox("No Results.")
rs.Close
db.Close
ws(0).Close
Set rs = Nothing
Set ws = Nothing
Set db = Nothing
If err.Number <> 0 then Msgbox err.description
End Sub
------------------------------------------------------
I hope this will help you...
Your solution would be like:
------------------------------------------------------
Private Sub CmdSearch_Click()
Dim ws as Dao.Workspaces
Dim db as Dao.database
Dim rs As RecordSet
Dim mysql As string
Dim search as String
On Error Resume Next
set ws = dbengine.workspaces
set db = ws(0).openDatabase(app.path & "\test.mdb".False.False)
search = Inputbox("Enter something to search: ")
mysql = "SELECT * FROM table_name WHERE field_u_want like '*" & search & "*'"
Set rs = db.OpenRecordSet(mysql)
If rs.recordcount = 0 Then Msgbox("No Results.")
rs.Close
db.Close
ws(0).Close
Set rs = Nothing
Set ws = Nothing
Set db = Nothing
If err.Number <> 0 then Msgbox err.description
End Sub
------------------------------------------------------
I hope this will help you...
@KSS: That thread is 5 years old 
The original poster must have already got the answer by now...
Also I will never recommend DAO. ADO is much faster

The original poster must have already got the answer by now...
Also I will never recommend DAO. ADO is much faster
A good excercise for the Heart is to bend down and help another up...
Please Mark your Thread "Solved", if the query is solved...
==>If a post has helped you then Please Rate it!
Please Mark your Thread "Solved", if the query is solved...
==>If a post has helped you then Please Rate it!
![]() |
Similar Threads
- how many records can Access table hold? (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Apply code to 'x' button on form
- Next Thread: Copy all folder contents to specified location(pls help)
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





