943,608 Members | Top Members by Rank

Ad:
Feb 22nd, 2005
0

Searching for records contained in access from VB

Expand Post »
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 :-)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lostprophet is offline Offline
5 posts
since Jan 2005
Feb 22nd, 2005
0

Re: Searching for records contained in access from VB

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.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Feb 28th, 2005
0

Re: Searching for records contained in access from VB

Quote 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?
Reputation Points: 49
Solved Threads: 11
Posting Whiz in Training
uniquestar is offline Offline
239 posts
since Feb 2005
Feb 28th, 2005
0

Re: Searching for records contained in access from VB

Quote 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
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Mar 11th, 2005
0

Re: Searching for records contained in access from VB

Try taking a look at my ADO tutorial http://www.timesheetsmts.com/adotutorial.htm
Reputation Points: 16
Solved Threads: 1
Posting Whiz in Training
mnemtsas is offline Offline
200 posts
since Jul 2004
Apr 12th, 2005
0

Re: Searching for records contained in access from VB

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mohsin Khan is offline Offline
8 posts
since Apr 2005
Mar 29th, 2009
0

Re: Searching for records contained in access from VB

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...
KSS
Reputation Points: 11
Solved Threads: 3
Newbie Poster
KSS is offline Offline
21 posts
since Mar 2009
Mar 29th, 2009
0

Re: Searching for records contained in access from VB

@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
Reputation Points: 11
Solved Threads: 6
Light Poster
koolsid is offline Offline
35 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Apply code to 'x' button on form
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Copy all folder contents to specified location(pls help)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC