Alert about existing records during data entry

Roddi

New member
Local time
Today, 11:05
Joined
Jun 26, 2014
Messages
8
I need to alert the user of the database in case he/she enters a record that already exists in the database. If a person enters a key type and a serial number combination that already exists in the system and has status “issued”, I need a pop up message to show up.
Can someone, please, tell me what is wrong with this code? Am I missing some quotation marks somewhere in that DCount?

Private Sub SerialNumber_AfterUpdate()

If DCount("*", "tblIssuedKeys", "KeyType = '" & Me.KeyType & "' And "Status = 'Issued'" And SerialNumber = '" & Me.SerialNumber & "'") > 0 Then

MsgBox "This key has already been issued"
Cancel = True
End If
End Sub

Thanks in advance!
 
You've got errant double quotes in the middle of your criteria:

& "' And "Status = 'Issued'" And SerialNumber = '"

There shouldn't be double quotes before Status nor after 'Issued'

Every double quote in the criteria (other than the starting and ending ones) should be either preceded or followed by an ampersand (&).
 
Thank you, Plog! It worked!
 

Users who are viewing this thread

Back
Top Bottom