•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 455,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,739 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 944 | Replies: 8
![]() |
•
•
Join Date: Oct 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
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
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
•
•
Join Date: Apr 2007
Posts: 69
Reputation:
Rep Power: 2
Solved Threads: 9
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.
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/d...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
Last edited by choudhuryshouvi : Nov 27th, 2007 at 12:05 pm.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
•
•
•
•
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
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Finding the nth row (SQL)...debative question (Software Developers' Lounge)
- Finding a Record in VB6 ADO (Visual Basic 4 / 5 / 6)
- finding the max date in a record (MS SQL)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
- DNS record types (PHP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Opening several excel files in one window
- Next Thread: VB60 reconnect to Excel instance


Linear Mode