944,135 Members | Top Members by Rank

Ad:
Nov 23rd, 2007
0

Synthax for finding a record:Re

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TOROOOLOLOOLO is offline Offline
16 posts
since Oct 2007
Nov 23rd, 2007
0

Re: Synthax for finding a record:Re

Your problem is on the MsgBox. Try the following:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Call MsgBox("Sorry, there is no such record found in the database with Employee ID :" & _
  2. Trim(txtsearch.Text) & "." & vbCrLf & "Please try again...", vbExclamation, "Employee")
Reputation Points: 53
Solved Threads: 13
Junior Poster
hopalongcassidy is offline Offline
148 posts
since Oct 2007
Nov 24th, 2007
0

Re: Synthax for finding a record:Re

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
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Nov 26th, 2007
0

Re: Synthax for finding a record:Re

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TOROOOLOLOOLO is offline Offline
16 posts
since Oct 2007
Nov 26th, 2007
0

Re: Synthax for finding a record:Re

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.
Reputation Points: 40
Solved Threads: 24
Junior Poster
SCBWV is offline Offline
125 posts
since Apr 2007
Nov 27th, 2007
0

Re: Synthax for finding a record:Re

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.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Nov 27th, 2007
0

Re: Synthax for finding a record:Re

Thanks Shouvik, can you please give me guidelines on how to use vb6's visual data manager to create the database.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TOROOOLOLOOLO is offline Offline
16 posts
since Oct 2007
Nov 27th, 2007
0

Re: Synthax for finding a record:Re

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.
Reputation Points: 40
Solved Threads: 24
Junior Poster
SCBWV is offline Offline
125 posts
since Apr 2007
Nov 29th, 2007
0

Re: Synthax for finding a record:Re

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
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007

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: Opening several excel files in one window
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB60 reconnect to Excel instance





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


Follow us on Twitter


© 2011 DaniWeb® LLC