From: chynewalker on
Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)

If DCount("[OEM_NUMBER]", _
"[ATLANTIS]", _
"[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then
If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?", vbYesNo)
= vbNo Then
Cancel = True
Else 'Do nothing
End If
End Sub


I just get an compile error when i use this



"PieterLinden via AccessMonster.com" wrote:

> 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
Don't know whether you've got a problem with word-wrap or not.

For the line

If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?", vbYesNo)
= vbNo Then

everything between "If" and "Then" should be on a single line.


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

"chynewalker" <chynewalker(a)discussions.microsoft.com> wrote in message
news:B89CF74E-55FB-48D9-95A8-6D0F3D2B1990(a)microsoft.com...
> Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)
>
> If DCount("[OEM_NUMBER]", _
> "[ATLANTIS]", _
> "[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then
> If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?",
> vbYesNo)
> = vbNo Then
> Cancel = True
> Else 'Do nothing
> End If
> End Sub
>
>
> I just get an compile error when i use this
>
>
>
> "PieterLinden via AccessMonster.com" wrote:
>
>> 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: chynewalker on
I fixed the word wrap, but it still get the error 'MB91443-20600"compile
error: block if without end if"

"Douglas J. Steele" wrote:

> Don't know whether you've got a problem with word-wrap or not.
>
> For the line
>
> If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?", vbYesNo)
> = vbNo Then
>
> everything between "If" and "Then" should be on a single line.
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://www.AccessMVP.com/DJSteele
> (no e-mails, please!)
>
> "chynewalker" <chynewalker(a)discussions.microsoft.com> wrote in message
> news:B89CF74E-55FB-48D9-95A8-6D0F3D2B1990(a)microsoft.com...
> > Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)
> >
> > If DCount("[OEM_NUMBER]", _
> > "[ATLANTIS]", _
> > "[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then
> > If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?",
> > vbYesNo)
> > = vbNo Then
> > Cancel = True
> > Else 'Do nothing
> > End If
> > End Sub
> >
> >
> > I just get an compile error when i use this
> >
> >
> >
> > "PieterLinden via AccessMonster.com" wrote:
> >
> >> 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: chynewalker on
Thanks everyone, I got it. I needed to add another "end if" and it works great

"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
>
From: Douglas J. Steele on
You've got two If statements, but only one End If. (Sorry I missed that
before)

Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)

If DCount("[OEM_NUMBER]", _
"[ATLANTIS]", _
"[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then

If MsgBox("This OEM already exists!!!" & vbcrlf & _
"Add it anyway?", vbYesNo) = vbNo Then
Cancel = True
Else 'Do nothing
End If

End If

End Sub

or

Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)

If DCount("[OEM_NUMBER]", _
"[ATLANTIS]", _
"[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then

Cancel = ("This OEM already exists!!!" & vbcrlf & _
"Add it anyway?", vbYesNo) = vbNo

End If

End Sub



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

"chynewalker" <chynewalker(a)discussions.microsoft.com> wrote in message
news:E50EBE08-5E00-403A-8132-971253206117(a)microsoft.com...
>I fixed the word wrap, but it still get the error 'MB91443-20600"compile
> error: block if without end if"
>
> "Douglas J. Steele" wrote:
>
>> Don't know whether you've got a problem with word-wrap or not.
>>
>> For the line
>>
>> If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?",
>> vbYesNo)
>> = vbNo Then
>>
>> everything between "If" and "Then" should be on a single line.
>>
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://www.AccessMVP.com/DJSteele
>> (no e-mails, please!)
>>
>> "chynewalker" <chynewalker(a)discussions.microsoft.com> wrote in message
>> news:B89CF74E-55FB-48D9-95A8-6D0F3D2B1990(a)microsoft.com...
>> > Private Sub OEM_NUMBER_BeforeUpdate(Cancel As Integer)
>> >
>> > If DCount("[OEM_NUMBER]", _
>> > "[ATLANTIS]", _
>> > "[OEM_NUMBER] = '" & Me.OEM_NUMBER & "'") Then
>> > If MsgBox("This OEM already exists!!!" & vbcrlf & "Add it anyway?",
>> > vbYesNo)
>> > = vbNo Then
>> > Cancel = True
>> > Else 'Do nothing
>> > End If
>> > End Sub
>> >
>> >
>> > I just get an compile error when i use this
>> >
>> >
>> >
>> > "PieterLinden via AccessMonster.com" wrote:
>> >
>> >> 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
>> >>
>> >> .
>> >>
>>
>>
>> .
>>