By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 800 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

How do I search a table in Access using Visual basic

P: 1
Hello,

Here is my current code ...

Dim rstStk As Recordset
Set rstStk = CurrentDb.OpenRecordset("Select * from stk where PartNum = '" & strPrt & "'")

The problem with this code is that i get a run time error if no record is found. How can i search the table differently where i can add a conditional statement so if no record is found, my code can do sometime else.

I really do need help. Thanks.
Mar 13 '07 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
Try this ...
Expand|Select|Wrap|Line Numbers
  1. Dim rstStk As Recordset
  2. Set rstStk = CurrentDb.OpenRecordset("Select * from stk where PartNum = '" & strPrt & "'")
  3.  
  4. If rstStk.RecordCount = 0 Then Exit Sub
  5.  
  6.  
Mar 13 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.