|
-
Sep 18th, 2004, 09:53 AM
#1
Thread Starter
Junior Member
Message box problem [Resolved]
VB Code:
Private Sub Command1_Click()
Dim Search As String
Dim sql As String
Search = InputBox("Enter Client ID", "Search Record")
data1.Recordset.FindFirst "[Client ID]= '" & Search & "'"
sql = "SELECT * FROM Table1 WHERE [Client ID] = '" & Search & "'"
data1.RecordSource = sql
data1.Refresh
If data1.Recordset.NoMatch Then
MsgBox "Record Not Found!", vbExclamation, "Search Record"
Else
MsgBox "Record Found!", vbInformation, "Search Record"
End If
End Sub
I wrote the above code to retrieve more than one records of a same client, and these records will be showed in a data grid. When record found/match, there will be a mesage box which displays "Record Found!", but the problem is when there is no record match, the message box still displays "Record Found!". I can't see anything wrong with the code/statement, any suggestion to make the message box display "Record Not Found!" when there is no record match?
Thanks in advance!
Last edited by hbin; Sep 20th, 2004 at 03:21 AM.
-
Sep 18th, 2004, 11:52 AM
#2
Insert this after the Refresh line:
VB Code:
Debug.Print data1.Recordset.NoMatch
My guess is that NoMatch's value is always zero/false. If it would be something else, you'd constantly get Not Found messagebox.
-
Sep 18th, 2004, 01:08 PM
#3
you prolly need to compare it to -1, 0, or 1. Use an = and an else.
it prolly returns -1 if not found or something like this that causes the false.
-
Sep 19th, 2004, 09:19 AM
#4
Thread Starter
Junior Member
VB Code:
Debug.Print data1.Recordset.NoMatch
I inseted it after the Refresh line but it still can't works. BTW, what is the meaning of Debug.Print?
-
Sep 19th, 2004, 09:26 AM
#5
There is a window called Immediate when your program is in runtime. When you use Debug.Print, the variable you give to it appears in the Immediate window. You can use this to find out the contents of your variables on runtime so you can debug your program and find out what might be wrong.
-
Sep 19th, 2004, 12:01 PM
#6
Thread Starter
Junior Member
I only see the word "False" in the Immediate window, what does that means?
-
Sep 19th, 2004, 12:05 PM
#7
that it did not find a match. it would have been true if it did.
-
Sep 19th, 2004, 12:09 PM
#8
try changing
Code:
If data1.Recordset.NoMatch Then
to
Code:
If data1.Recordset.NoMatch = True Then
is the Search the same data type as ID is?
-
Sep 19th, 2004, 12:34 PM
#9
Thread Starter
Junior Member
Originally posted by dglienna
try changing
Code:
If data1.Recordset.NoMatch Then
to
Code:
If data1.Recordset.NoMatch = True Then
is the Search the same data type as ID is?
I tried your code, but it is still the same.
Yeah, the Search is the same data type as ID, which is String.
-
Sep 19th, 2004, 01:03 PM
#10
Can you put together a small project (including data) that shows the same problem and attach it?
-
Sep 19th, 2004, 02:44 PM
#11
use debug.print to check each value. or else step through.
-
Sep 19th, 2004, 11:45 PM
#12
Member
Try the ffg. codes:
Dim Search As String
Dim sql As String
Search = InputBox("Enter Client ID", "Search Record")
sql = "SELECT * FROM Table1 WHERE [Client ID] = '" & Search & "'"
data1.RecordSource = sql
data1.Refresh
if data1.recordset.bof and data1.recordset.eof then
MsgBox "Record Not Found!", vbExclamation, "Search Record"
else
MsgBox "Record Found!", vbInformation, "Search Record"
End If
-
Sep 20th, 2004, 03:18 AM
#13
Thread Starter
Junior Member
Thanks ponjaps, your code work!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|