I'm trying to validate two values on a form against the database to make sure that they exist, check number and check amount - if they are the same as what's in the table then open up a form, else a msgbox saying the data entered is wrong.
I tried a sql statement but the window opens even if the data from the form is not correct.
Is there a better way to work with an empty recordset to make an event?
I tried a sql statement but the window opens even if the data from the form is not correct.
Code:
CHECK_NUMBER = Me.txtChkNum
CHECK_AMOUNT = Format(Me.txtChkAmount, "########0.00")
CHKAMT = CVar(CHECK_AMOUNT)
sqlstr = ""
sqlstr = sqlstr & " SELECT tblMainTable.CHECK_NUMBER as CHKNUMB, tblMainTable.AMOUNT "
sqlstr = sqlstr & " FROM tblMainTable "
sqlstr = sqlstr & " WHERE (((tblMainTable.CHECK_NUMBER)= " & CHECK_NUMBER & ") "
sqlstr = sqlstr & " AND ((tblMainTable.AMOUNT)= " & CHECK_AMOUNT & ")) "
'Debug.Print sqlstr
rec2.Open sqlstr, con, adOpenDynamic
If IsNull(rec2!AMOUNT) Then
MsgBox "Check does not exist in database, please re-enter.", vbOKOnly, "Ooops"
Else
stDocName = "frmSpecialHandling"
DoCmd.OpenForm stDocName, , , "[CHECK_NUMBER] = " & Me.txtChkNum
Is there a better way to work with an empty recordset to make an event?