if value not found in table ?

  • Thread starter Thread starter erick-flores
  • Start date Start date
E

erick-flores

Hello all

I need to display a msgbox if a value is not found in a table.

Something like:

If value not_in table.field then
msgbix
end if

I know that code wont work is just an ilustration of what i am looking
for


Thanks in advance
 
Use DLookup() to see if the value is in the table.

If it's not found, the result will be Null.
So, use IsNull() to test the result.

Here's how to get your Dlookup() expression working:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
Something like the following will do it

Dim db As DAO.Database
Dim rst As DAO.Recordset

strSQL = "SELECT [FieldToCheck] FROM [TableToCheck] WHERE
[First]='ValueToCheckFor'"
Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL)

If rst.RecordCount = 0 Then
MsgBox "Hey it's not in the table!"
End If

Set rst = Nothing
Set db = Nothing
 
I decided to use Daniel's suggestion it did the work.

Thank you all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top