IF statement help.

P

p-rat

I have a form that I need help with. I have a field that is unique
(primary key) and there is code that looks for this field and if it is
a duplicate there is an error message that pops up. I would like to
revise the code to where a message box pops up asking 'Is this for
Multiple Disposal Site ticket?'. Then if user clicks 'yes' then it
will allow the duplicate; if no then go back to original code to
cancel out. I am not the original designer of this and have very
limited skills in Access. If anyone can help me out if would be
greatly appreciated. Here is the code:


Private Sub dbo_Field_Ticket_Header_Field_Ticket_Number_BeforeUpdate
(Cancel As Integer)
Dim lngField_Ticket_Number As Long, strCriteria As String
If IsNumeric(Me.dbo_Field_Ticket_Header_Field_Ticket_Number) Then
lngField_Ticket_Number =
Me.dbo_Field_Ticket_Header_Field_Ticket_Number
strCriteria = "[Field_Ticket_Number] = " &
lngField_Ticket_Number
If SearchTableByCriteria("dbo_Field_Ticket_Header",
strCriteria) Then
MsgBox "That ticket number already exists in the database.
Please enter another ticket number.", vbExclamation
Cancel = True
End If
Else
MsgBox "INVALID TICKET NUMBER.", vbExclamation
Cancel = True
End If

End Sub
 
D

Dorian

Then if user clicks 'yes' then it
will allow the duplicate;

You cannot have a duplicate primary key, so your question does not seem to
make sense?

-Dorian

p-rat said:
I have a form that I need help with. I have a field that is unique
(primary key) and there is code that looks for this field and if it is
a duplicate there is an error message that pops up. I would like to
revise the code to where a message box pops up asking 'Is this for
Multiple Disposal Site ticket?'. Then if user clicks 'yes' then it
will allow the duplicate; if no then go back to original code to
cancel out. I am not the original designer of this and have very
limited skills in Access. If anyone can help me out if would be
greatly appreciated. Here is the code:


Private Sub dbo_Field_Ticket_Header_Field_Ticket_Number_BeforeUpdate
(Cancel As Integer)
Dim lngField_Ticket_Number As Long, strCriteria As String
If IsNumeric(Me.dbo_Field_Ticket_Header_Field_Ticket_Number) Then
lngField_Ticket_Number =
Me.dbo_Field_Ticket_Header_Field_Ticket_Number
strCriteria = "[Field_Ticket_Number] = " &
lngField_Ticket_Number
If SearchTableByCriteria("dbo_Field_Ticket_Header",
strCriteria) Then
MsgBox "That ticket number already exists in the database.
Please enter another ticket number.", vbExclamation
Cancel = True
End If
Else
MsgBox "INVALID TICKET NUMBER.", vbExclamation
Cancel = True
End If

End Sub
 

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

Similar Threads


Top