Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search failures

Status
Not open for further replies.

rundmc

Programmer
Jan 16, 2003
15
US
Anyone know where best in the following piece of code to give the user notification that no results have been returned from the search and what sort of code might be suitable....

urgent!

Thanks

Private Sub CmdSearch_Click()
MSFlexGrid1.FormatString = &quot; <|PC ID |<PC Vendor |<PC Make/Model |<Memory |<Operating System |<Location |< Business Dept ID&quot;


Dim adoconnection As ADODB.Connection
Set adoconnection = New ADODB.Connection

adoconnection.Open (&quot;Provider=Microsoft.jet.oledb.4.0;&quot; & &quot;Data Source =H:\AssetTracking.mdb&quot;)


MSFlexGrid1.Visible = True

Set rs = New ADODB.Recordset




rs.Open &quot;select * from PC where PCMakeModel ='&quot; & TxtMakeModel.Text & &quot;' and BusinessDeptID ='&quot; & TxtBU.Text & &quot;'&quot;, adoconnection, adOpenDynamic, adLockOptimistic





Dim irow As Integer

With MSFlexGrid1




.Rows = 2
If ((Not rs.EOF) Or (Not rs.EOF)) Then
rs.MoveFirst
Do While (Not rs.EOF)
irow = .Rows - 1
.TextMatrix(irow, 1) = rs!PCID
.TextMatrix(irow, 2) = rs!PCVendor
.TextMatrix(irow, 3) = rs!PCMakeModel
.TextMatrix(irow, 4) = rs!Memory
.TextMatrix(irow, 5) = rs!OperatingSystem
.TextMatrix(irow, 6) = rs!Location
.TextMatrix(irow, 7) = rs!BusinessDeptID
.Rows = .Rows + 1
rs.MoveNext
Loop


If (.Rows > .FixedRows) Then
.Rows = .Rows - 1
End If
End If
End With




End Sub

 
Right after rs.open write a check for rs.recordcount
if it is 0 then pop a message, clear your variables, and exit the Sub
 
I would put the notification is the Else clause of the outer conditional.

If ((Not rs.EOF) Or (Not rs.EOF)) Then
rs.MoveFirst
...
Else
MsgBox &quot;No Records Returned&quot;
End If

I hope that after the nine posts you've made so far, you've found some of the helpful, and have been willing to express at least some appreciation to those who have given of their time to help you. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top