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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validation check in code

Status
Not open for further replies.

haytatreides

IS-IT--Management
Oct 14, 2003
94
US
i have a primary key that is identical in two tables. I have a form that populates table2, but i need to check to make sure that the primary key (order_number) isn't already present in table2. is there a way to write some code that will check this, and then generate a dialog box informing the user? I figure either a loop that check individual records (which might be the long hard way), or finding out the error number and making a default msgbox. any suggestions from anyone?

hayt
 
apperently when it give me an error, it isnt a dataErr, it is on the .update code. so now i am sol.
 
nevermind, i was stupid and forgot with run-time errors it is a different code (-2147217873) and i needed a on error goto line of code!!! Sorry all.
 
I'm not sure which method you are using, but if you are refering to a TableType Recordset (Jet, ADO, or DAO), you can use the Seek Method to check.

Example:

Private Sub tbxPID_BeforeUpdate(Cancel as Integer)
rstTbl2.Index = "fldPID"
rstTbl2.Seek "=", CStr(Me.tbxPID.Value)
If rstTbl2.NoMatch Then
'There is no record with the ID number that's in the textbox
Else
MsgBox "There is already a record with this particular ID Number.",48
Cancel = -1
End If
End Sub

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top