vba coding to cross-check values in another table based on a value entered in a form using a recordset

I have a form called "Labor Tracker" whose data source is a table called "Labor".  In this form, the user enters information for three fields called

1. IITR (integer)
2. WorkOrderNo (text)

In the before update event of this form, I would like a table called "iitdata" to be opened, where vba checks the "IITReportNo" field (integer) and checks for a matching IITR value AND checks the "ReceiverNo" field (text) and checks for a matching WorkOrderNo.  If neither matches are found, an error message stating that the IITR and/or WorkOrderNo are incorrect.  So IITR should map to IITReportNo and WorkOrderNo maps to ReceiverNo.

I only got so far as to open the iitdata table as a recordset but am not sure how to now perform the check.  I could really use expert help please.  Thanks.
Dim db As DAO.Database
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcErr

Dim rst As DAO.Recordset
Dim rstcount As Integer
Dim TableName As String

TableName = "iitdata"

Set db = CurrentDb
Set rst = db.OpenRecordset(TableName)

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill RossProgrammerCommented:

You can easily look up a value using the dlookup function.  Check help for the syntax but it will return a unique valu for the column and row.  I think in your case you would need something like:

dim valuefound
valuefound=dlookup("IITReportNo","iitdata","ReceiverNo='" & me!WorkOrderNo & "'")
if isnull(valuefound) or me!IITR <> valuefound  then
  msgbox "Not found or invalid IITR."

This is rough but may get you started.

BTW - use the after update of the fields - not the form.



Note that you need to put single quotes around the WorkOrderNo field since it's text.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sxxguptaAuthor Commented:
Thanks Bill!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.