can you please help me in vb6.

The program is like this:
In the program you want to search a name in the databse. In order to do that you must enter a value in the textbox and click the search command button.

can you help me guyss!! geezz thank you

Recommended Answers

All 22 Replies

Use the following -

Private Sub Command1_Click()

Dim con As ADODB.Connection
Set con = New ADODB.Connection

Dim rsSearch As ADODB.Recordset
Set rsSearch = New ADODB.Recordset

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\MyDatabaseName.MDB;Persist Security Info=False"
    
rsSearch.Open "SELECT * FROM MyTableName WHERE MyField LIKE " & "'" & Text1.Text & "'", con, adOpenStatic, adLockOptimistic
'The LIKE function searches the database fo names that is similar than what you typed in text1...

If rsSearch.EOF = True Or rsSearch.BOF = True Then
    MsgBox "No Record Found"
        Else
    'Do here what you need if the file was found...
End If

rsSearch.Close
con.Close
End Sub

there's seem to be an error around this part:

rsSearch.Open "SELECT * FROM MyTableName WHERE MyField LIKE " & "'" & Text1.Text & "'", con, adOpenStatic, adLockOptimistic

my Datbase name is Book List and my Fieldname is Title of Books.

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\[Book List].MDB;Persist Security Info=False"

rsSearch.Open "SELECT * FROM MyTableName WHERE [Title of Books] LIKE " & "'" & Text1.Text & "'", con, adOpenStatic, adLockOptimistic

Change the "MyTableName" as well.

STill the program says

Object Required in this part

rsSearch.Open "SELECT * FROM Books WHERE [Title of Books] LIKE " & "'" & Text1.Text & "'", con, adOpenStatic, adLockOptimistic

It is looking for the data active x object library. Did you reference it?

Top menu -

Project/references/MS Active X Data Objects 2.x (x is the version on your pc)

In vb6, go to the top menu.
Click on Project
In the list, click on References
When the reference dialog list opens, select "Microsoft Active X Data Objects 2.8"
Click on OK

Now test the code again.:)

i already done that part..thanks for the help sir

If that part is done, where does the error occur? Post the code here for me, thanks.

Please post soon, I need to go offline in the next half hour. I would like to solve your problem before then.:)

I think I have a complication with my MSDN, that's why the projrct>reference>MS ACTIVE X DATA onjects" are not running

Ok, what version of VB6 do you have, enterprise, professional etc?

Can you see the "project/references" menu?

I have a problem at the back-end which is the MSDN..but the code is alright I think

I then hope you find a solution to get the data objects sorted soon. Happy coding:)

Please mark this as solved (found at the bottom of this page), as the original question was answered, thanks.:)

@tin1296, please mark this thread as solved if you have managed to get a solution, found at the bottom of this page, thanks.:)

It has been open for some time now.

hi i read this thread and it help me a lot with my school project..but it would help me more if you'll help me with the Do Statement..i want to display the results..how will i do it??

please help me with the codes..thanks a lot.. :)))

hi i read this thread and it help me a lot with my school project..but it would help me more if you'll help me with the Do Statement..i want to display the results..how will i do it??

Dim Search as string
Search = text1.text
'First, input your Connection string from your database then in the Recordset
'Use this code
RS.Open "Select * from YourTable where FirstName like '" & Search & "%'", DB, 3, 3
Do Until RS.EOF
    Rs.Movenext
    MsgBox "Found"
Loop

Hi @AndreRet,
ur code really help me.. thanks. ^___^"
im new in vb6 ..huhu...

Via using the select query from above (shown below), how would you write an update database command in this format?

rsSearch.Open "SELECT * FROM MyTableName WHERE MyField LIKE " & "'" & Text1.Text & "'", con, adOpenStatic, adLockOptimistic

Via using the select query from above (shown below), how would you write an update database command in this format?

rsSearch.Open "SELECT * FROM MyTableName WHERE MyField LIKE " & "'" & Text1.Text & "'", con, adOpenStatic, adLockOptimistic

I've been using rsSearch.Open "UPDATE [TableName] SET [Field2] = " & "'" & "[Value from VB6]" & "'" WHERE [Field1] = & "'" & [Value from VB6]" & "'", con, adOpenKeyset, adLockOptimistic

I'm getting a compile error Expected: end of statement message box, where it highlights the term WHERE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.