Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: IF statement help.

Geek News

IF statement help.
p-rat <osupratt[ at ]yahoo.com> 12/8/2008 4:28:12 PM
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
RE: IF statement help.
Dorian 12/8/2008 5:17:01 PM
[Quoted Text]
>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" wrote:

> 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
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net