943,551 Members | Top Members by Rank

Ad:
Nov 18th, 2008
0

What's wrong with my "searching" code?

Expand Post »
Hello everybody...
I'have bound a database to my form, and it displays the record of some fields from my database. I want to make the displayed record so that it can be searched by clicking the "find" button by the related searching categories. Below are coding that i've used..

[Private Sub Command2_Click()
prompt$ = "Sila masukkan nombor rujukan permohonan yang berkenaan."
'get string to be used in the Nombor Rujukan field search
SearchStr$ = InputBox(prompt$, "Mencari rekod berdasarkan nombor rujukan")
Data1.Recordset.Index = "ReferenceNumb" 'use reference numb database field
Data1.Recordset.Seek "=", SearchStr$ 'and search
If Data1.Recordset.NoMatch Then 'if no match
Data1.Recordset.MoveFirst 'go to first record
End If
End Sub]

[Private Sub Command2_Click()
prompt$ = "Sila masukkan nombor rujukan permohonan yang berkenaan."
'get string to be used in the Nombor Rujukan field search
SearchStr$ = InputBox(prompt$, "Mencari rekod berdasarkan nombor rujukan")
Data1.Recordset.Index = "ReferenceNumb" 'use reference numb database field
Data1.Recordset.Seek "=", SearchStr$ 'and search
If Data1.Recordset.NoMatch Then 'if no match
Data1.Recordset.MoveFirst 'go to first record
End If
End Sub]

[Private Sub Command4_Click()
prompt$ = "Sila masukkan status permohonan berkenaan. Samada Approved atau Not approved"
'get string to be used in the status field search
SearchStr$ = InputBox(prompt$, "Mencari rekod berdasarkan status permohonan")
Data1.Recordset.Index = "Status" 'use status database field
Data1.Recordset.Seek "=", SearchStr$ 'and search
If Data1.Recordset.NoMatch Then 'if no match
Data1.Recordset.MoveFirst 'go to first record
End If
End Sub]

Sorry for using some Malay language words in the above coding. I hope anybody experts in this field could kindly plz tell me, what's wrong with the coding, since i got the coding from a Microsoft Press book. (Microsoft VB6 Professional Step By Step, 2nd Edition).

For your information, i'm using VB6.0 with service pack 6.0, and create the database using Microsoft Access 2003.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
nor_d83 is offline Offline
28 posts
since Aug 2008
Nov 18th, 2008
0

Re: What's wrong with my "searching" code?

Hi,

If the field you are trying to SEEK is a String, then you have to wrap the search string with single quotes.. Also, SEEK works if the Recordset is open in TABLE mode, and INDEX has been defined..

Data1.Recordset.Seek "=", "'" & SearchStr$ & "'"

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Nov 18th, 2008
0

Re: What's wrong with my "searching" code?

Thanx for your reply.. Could you plz tell me how to define the INDEX, and what is it actually? plz...
Reputation Points: 10
Solved Threads: 0
Light Poster
nor_d83 is offline Offline
28 posts
since Aug 2008
Nov 18th, 2008
0

Re: What's wrong with my "searching" code?

So far, i had used [Data1.Recordset.Seek "=", "'" & SearchStr$ & "'"] as recommended. And then, the recordset was and is in TABLE mode.. But, the result is still the same error.. Which is 'Run-time error 3800'. '..is not an index in this table'..
The problem is, could u plz guide me how to define the index.. Plz... My teacher want me to solve this by myself..
Reputation Points: 10
Solved Threads: 0
Light Poster
nor_d83 is offline Offline
28 posts
since Aug 2008
Nov 18th, 2008
0

Re: What's wrong with my "searching" code?

You have to go to visual data manager assuming your using vb6.0, its on the add-ins menu, then open your database, right click on the table you need and select design, on the bottom left corner you will see the index fields, click add index, next a window will pop-up and you just have to select the categories on which you wish to make your searches on, be sure to leave the check boxes unselected click ok and your done.
Reputation Points: 11
Solved Threads: 1
Newbie Poster
Juanon is offline Offline
2 posts
since Nov 2008
Nov 18th, 2008
0

Re: What's wrong with my "searching" code?

Thanx lot Juanon for the knowledges given to me.. I tried it... But VisData cannot even display the database. It said,"Unrecognized database format. Number 3343, Display the data access errors collection?" For your information, i've made the database (a very simple one) using Access 2003. Or is it incompatible with VB6.0? Plz sumbody help me..

p/s: Here i attach my database in zip file.. It';s very simple one..
Attached Files
File Type: zip allotment request.zip (16.9 KB, 48 views)
Reputation Points: 10
Solved Threads: 0
Light Poster
nor_d83 is offline Offline
28 posts
since Aug 2008
Nov 19th, 2008
1

Re: What's wrong with my "searching" code?

Create the database from VisData not from access
Reputation Points: 11
Solved Threads: 1
Newbie Poster
Juanon is offline Offline
2 posts
since Nov 2008
Nov 20th, 2008
1

Re: What's wrong with my "searching" code?

Hi,

Index should be the Index name and not the Fieldname..

Data1.Recordset.Index = "indStatus"

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Nov 22nd, 2008
0

Re: What's wrong with my "searching" code?

Both of u are great VB teachers! Thanx lot for your generously help and guides. May God bless u always...
Reputation Points: 10
Solved Threads: 0
Light Poster
nor_d83 is offline Offline
28 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: searching for files and subfolders recursively from an FTP
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Beginner help for visual basic





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


Follow us on Twitter


© 2011 DaniWeb® LLC