From: chynewalker on

I created this code to pop a box up that will let me know when i have a
duplicate number, however, I want to still be able to write a duplicate entry.

Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)

If DCount("[OEM_NUMBER]", _
"[ATLANTIS]", _
"[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then
MsgBox "This oem number already exists!!!"
Cancel = True
Else 'Do nothing
End If
End Sub

From: Mike Painter on
chynewalker wrote:
> I created this code to pop a box up that will let me know when i have
> a duplicate number, however, I want to still be able to write a
> duplicate entry.
>
> Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)
>
> If DCount("[OEM_NUMBER]", _
> "[ATLANTIS]", _
> "[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then
> MsgBox "This oem number already exists!!!"
> Cancel = True
> Else 'Do nothing
> End If
> End Sub

If msgbox("This oem number already exists allow?",vbYesNo, "allow") = False
then
Cancel = True
end if


From: PieterLinden via AccessMonster.com on
chynewalker wrote:
>I created this code to pop a box up that will let me know when i have a
>duplicate number, however, I want to still be able to write a duplicate entry.
>
>Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)
>
>If DCount("[OEM_NUMBER]", _
>"[ATLANTIS]", _
>"[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then
>MsgBox "This oem number already exists!!!"
>Cancel = True
>Else 'Do nothing
>End If
>End Sub

You need to put the Cancel = True inside another If statement.

e.g.
If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?", vbYesNo)
= vbNo Then
Cancel = True
Else...

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201003/1

From: Douglas J. Steele on
"Mike Painter" <md.painter(a)sbcglobal.net> wrote in message
news:YCvnn.113286$0N3.5478(a)newsfe09.iad...
>
> If msgbox("This oem number already exists allow?",vbYesNo, "allow") =
> False then
> Cancel = True
> end if

No, you'd need

If msgbox("This oem number already exists allow?",vbYesNo, "allow") = vbNo
then
Cancel = True
end if

Both vbYes and vbNo, the two possible values the msgbox function would
return in this case, are non-zero, so they'd both be treated as True.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)



From: Mike Painter on
Douglas J. Steele wrote:
> "Mike Painter" <md.painter(a)sbcglobal.net> wrote in message
> news:YCvnn.113286$0N3.5478(a)newsfe09.iad...
>>
>> If msgbox("This oem number already exists allow?",vbYesNo, "allow")
>> = False then
>> Cancel = True
>> end if
>
> No, you'd need
>
> If msgbox("This oem number already exists allow?",vbYesNo, "allow")
> = vbNo then
> Cancel = True
> end if
>
> Both vbYes and vbNo, the two possible values the msgbox function would
> return in this case, are non-zero, so they'd both be treated as True.

I'll get back to you as soon as I think of an excuse.

Thanks.