Searching for records contained in access from VB

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2005
Posts: 5
Reputation: lostprophet is an unknown quantity at this point 
Solved Threads: 0
lostprophet lostprophet is offline Offline
Newbie Poster

Searching for records contained in access from VB

 
0
  #1
Feb 22nd, 2005
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 :-)
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: Searching for records contained in access from VB

 
0
  #2
Feb 22nd, 2005
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)
  1. Dim Sql as String
  2.  
  3. Sql = "SELECT * FROM Table WHERE Str = '" & txtInputBox & "'"
  4. 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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 238
Reputation: uniquestar is an unknown quantity at this point 
Solved Threads: 11
uniquestar's Avatar
uniquestar uniquestar is offline Offline
Daniweb Sponsor

Re: Searching for records contained in access from VB

 
0
  #3
Feb 28th, 2005
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)
  1. Dim Sql as String
  2.  
  3. Sql = "SELECT * FROM Table WHERE Str = '" & txtInputBox & "'"
  4. 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.
Hi, I just tried using this code, but got a whole load of run-time errors, doesn't seem to work with ADODC
do you have anything else?
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: Searching for records contained in access from VB

 
0
  #4
Feb 28th, 2005
Originally Posted by uniquestar
doesn't seem to work with ADODC
do you have anything else?
Sorry, 90% of my work is done in assembly and the other in C++. DAO is the only thing I've ever used with VB
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Searching for records contained in access from VB

 
0
  #5
Mar 11th, 2005
Try taking a look at my ADO tutorial http://www.timesheetsmts.com/adotutorial.htm
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 8
Reputation: Mohsin Khan is an unknown quantity at this point 
Solved Threads: 0
Mohsin Khan Mohsin Khan is offline Offline
Newbie Poster

Re: Searching for records contained in access from VB

 
0
  #6
Apr 12th, 2005
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"

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Persist Security Info=False"
  3. Adodc1.CommandType = adCmdText
  4. Adodc1.RecordSource = "select name from t1 where invoice like '" & Textbox1.Text & "'"
  5. Adodc1.Refresh
  6. If Adodc1.Recordset.RecordCount > 0 Then
  7. Textbox1.Text=Adodc1.Recordset.Fields(0)
  8. End if
  9. End Sub
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: KSS is an unknown quantity at this point 
Solved Threads: 1
KSS's Avatar
KSS KSS is offline Offline
Newbie Poster

Re: Searching for records contained in access from VB

 
0
  #7
Mar 29th, 2009
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...
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 35
Reputation: koolsid is an unknown quantity at this point 
Solved Threads: 6
koolsid's Avatar
koolsid koolsid is offline Offline
Light Poster

Re: Searching for records contained in access from VB

 
0
  #8
Mar 29th, 2009
@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
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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC