Hi
I am still facing problems after writing the codes for finding a record. A compile error occurs, which says
"User-defined type not defined" .I don't understand what it means or even how to go about it. please i need help.The following are the codes i wrote for the program;

Option Explicit

Dim db As Database
Dim rs As Recordset

Private Sub cmdsearch_Click()
If Trim(txtsearch.Text) <> "" Then
Set rs = db.OpenRecordset("select * from details where id='" & Trim(txtsearch.Text) & "'")
If rs.RecordCount > 0 Then
txtid.Text = rs!id
txtname.Text = rs!Name
txtbasic.Text = rs!basic
txtsearch.SelStart = 0
txtsearch.SelLength = Len(Trim(txtsearch.Text))
txtsearch.SetFocus
Else
MsgBox "Sorry, there is no such record found in the database with Employee ID :" & _
Trim(txtsearch.Text) & "." & vbCrLf & "Please try again...", vbExclamation, "Employee"
txtid.Text = ""
txtname.Text = ""
txtbasic.Text = ""
txtsearch.SelStart = 0
txtsearch.SelLength = Len(Trim(txtsearch.Text))
txtsearch.SetFocus
End If
Else
MsgBox "Please mention the employee id to search for.", vbExclamation, "Employee"
txtsearch.SetFocus
End If
End Sub

Private Sub Form_Load()
Set db = OpenDatabase(App.Path & "\employee.mdb")
Set rs = db.OpenRecordset("details", dbOpenTable)

If rs.RecordCount > 0 Then
rs.MoveFirst
Else
MsgBox "Please add some records to the database before you try to search.", vbInformation, "Employee"
End If
End Sub

Your problem is on the MsgBox. Try the following:

Call MsgBox("Sorry, there is no such record found in the database with Employee ID :" & _
Trim(txtsearch.Text) & "." & vbCrLf & "Please try again...", vbExclamation, "Employee")

hi TORO it's Shouvik again. i think that is my code which i posted to ur previous thread. here is the answer for ur question :-

there is no error in the above code at all. all the syntaxes and calling procedures,functions are absolutely correct. the msgbox callout is also completely ok. u have the problem in the dao reference which u have forgotten to include into ur project.to add it goto project->references, scroll down and select "Microsoft DAO 3.51 Object Library" and click ok. after this run the program and there will be no error at all. it's a promise. and by the way thanks for ur comment for my reply to ur previous post. keep contacting me.

regards
Shouvik

Thanks Shouvk for the support, but still there is a problem when i run the program. A run-time error '3343': occurs. It says "unrecognised database format 'C:\Documents and Settings\Sugar\My Documents\VBpro\toroo\Employee.mdb ' .
Need help to fix this problem.

What database version format are you using? What version of DAO are you using?

Also, if you're working strictly with strings, you should use the specific versions of Left$(), Mid$(), Right$(), Chr$(), ChrW$(), UCase$(), LCase$(), LTrim$(), RTrim$(), Trim$(), Space$(), String$(), Format$(), Hex$(), Oct$(), and Str$().

Otherwise, VB uses the Variant version, which is much slower.

Thanks Shouvk for the support, but still there is a problem when i run the program. A run-time error '3343': occurs. It says "unrecognised database format 'C:\Documents and Settings\Sugar\My Documents\VBpro\toroo\Employee.mdb ' .
Need help to fix this problem.

have you created the database by using ms-access software of versions higher than office 97???
if yes then i'm sorry to say that you cannot access the database from vb. because vb6 has the limitation on accessing the Access databases rather than office97 format. in such circumstances you have to create the database using vb6's visual data manager. then there will be no problem in accessing the database from your vb program. now if you don't wish to do this then you need to install the service pack 4 patch of vb6. visit the following link to get the vb6 service pack 6 files :- http://www.microsoft.com/downloads/details.aspx?familyid=7b9ba261-7a9c-43e7-9117-f673077ffb3c&displaylang=en

after you have downloaded the above file, install it and then try to run your program. there should not be any problem now.

regards
Shouvik

Thanks Shouvik, can you please give me guidelines on how to use vb6's visual data manager to create the database.

VB6 can use Access files in other versions. I do it all the time with Access 2000 and 2003. You just have to load the correct DAO version.

Thanks Shouvik, can you please give me guidelines on how to use vb6's visual data manager to create the database.

it's a long time process. have you tried your program after downloading and installing the patch files yet??? first try it and if it won't work i'll surely tell you the steps.

regards
Shouvik

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.