Hi,
I'm trying to prevent a duplicate entry of a number in a particular
field in a form, however, whenever I enter the data it gives me the
error "Run Time Error 2001" you cancelled the previous operation.
The weird thing is that I have this exact same code running in another
form just fine. The only thing different is that one is a txt field
and the other is an integer. I've tried both DLookup and DCount as
shown in my sample code below. Any ideas?
Private Sub SO__BeforeUpdate(Cancel As Integer)
If IsNull([SO#]) Then
Exit Sub
End If
Dim varTemp1 As Variant
varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = Me![SO#]")
If varTemp1 = Me![SO#] Then
MsgBox "Duplicate!", vbOKOnly, "Duplicate SO Number Found"
End If
End Sub
______________________________________________________________
If DCount("*", "RMA INFO", "[SO#] = Me.SO_.Value") > 0 Then
MsgBox "You have entered a value that is already in the
table!"
Me.Undo
End If
______________________________________________________________
|
|
0
|
|
|
|
Reply
|
AJ
|
6/21/2007 6:16:48 PM |
|
You need to put the reference to the control outside of the quotes.
varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = " & Me![SO#])
That assumes SO# is numeric. If it's text, try
varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = '" & Me![SO#] & "'")
Exagerated for clarity, that's
varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = ' " & Me![SO#] & " ' ")
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"AJ" <aspoede@gmail.com> wrote in message
news:1182449808.488409.206090@e9g2000prf.googlegroups.com...
> Hi,
>
> I'm trying to prevent a duplicate entry of a number in a particular
> field in a form, however, whenever I enter the data it gives me the
> error "Run Time Error 2001" you cancelled the previous operation.
>
> The weird thing is that I have this exact same code running in another
> form just fine. The only thing different is that one is a txt field
> and the other is an integer. I've tried both DLookup and DCount as
> shown in my sample code below. Any ideas?
>
> Private Sub SO__BeforeUpdate(Cancel As Integer)
>
>
> If IsNull([SO#]) Then
> Exit Sub
> End If
>
> Dim varTemp1 As Variant
>
> varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = Me![SO#]")
>
> If varTemp1 = Me![SO#] Then
> MsgBox "Duplicate!", vbOKOnly, "Duplicate SO Number Found"
> End If
> End Sub
>
> ______________________________________________________________
>
> If DCount("*", "RMA INFO", "[SO#] = Me.SO_.Value") > 0 Then
> MsgBox "You have entered a value that is already in the
> table!"
> Me.Undo
> End If
>
> ______________________________________________________________
>
|
|
0
|
|
|
|
Reply
|
Douglas
|
6/21/2007 6:35:40 PM
|
|
On Jun 21, 1:35 pm, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
> You need to put the reference to the control outside of the quotes.
>
> varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = " & Me![SO#])
>
> That assumes SO# is numeric. If it's text, try
>
> varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = '" & Me![SO#] & "'")
>
> Exagerated for clarity, that's
>
> varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = ' " & Me![SO#] & " ' ")
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no e-mails, please!)
>
> "AJ" <aspo...@gmail.com> wrote in message
>
> news:1182449808.488409.206090@e9g2000prf.googlegroups.com...
>
> > Hi,
>
> > I'm trying to prevent a duplicate entry of a number in a particular
> > field in a form, however, whenever I enter the data it gives me the
> > error "Run Time Error 2001" you cancelled the previous operation.
>
> > The weird thing is that I have this exact same code running in another
> > form just fine. The only thing different is that one is a txt field
> > and the other is an integer. I've tried both DLookup and DCount as
> > shown in my sample code below. Any ideas?
>
> > Private Sub SO__BeforeUpdate(Cancel As Integer)
>
> > If IsNull([SO#]) Then
> > Exit Sub
> > End If
>
> > Dim varTemp1 As Variant
>
> > varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = Me![SO#]")
>
> > If varTemp1 = Me![SO#] Then
> > MsgBox "Duplicate!", vbOKOnly, "Duplicate SO Number Found"
> > End If
> > End Sub
>
> > ______________________________________________________________
>
> > If DCount("*", "RMA INFO", "[SO#] = Me.SO_.Value") > 0 Then
> > MsgBox "You have entered a value that is already in the
> > table!"
> > Me.Undo
> > End If
>
> > ______________________________________________________________
That worked like a charm! Thanks so much. I knew I was just messing
up some syntax.
|
|
0
|
|
|
|
Reply
|
AJ
|
6/21/2007 7:17:49 PM
|
|
Once you apply Doug's suggestion, don't forget to add the all important:
Cancel = True
if a match is found.
HTH,
"AJ" <aspoede@gmail.com> wrote in message
news:1182449808.488409.206090@e9g2000prf.googlegroups.com...
> Hi,
>
> I'm trying to prevent a duplicate entry of a number in a particular
> field in a form, however, whenever I enter the data it gives me the
> error "Run Time Error 2001" you cancelled the previous operation.
>
> The weird thing is that I have this exact same code running in another
> form just fine. The only thing different is that one is a txt field
> and the other is an integer. I've tried both DLookup and DCount as
> shown in my sample code below. Any ideas?
>
> Private Sub SO__BeforeUpdate(Cancel As Integer)
>
>
> If IsNull([SO#]) Then
> Exit Sub
> End If
>
> Dim varTemp1 As Variant
>
> varTemp1 = DLookup("[SO#]", "RMA INFO", "[SO#] = Me![SO#]")
>
> If varTemp1 = Me![SO#] Then
> MsgBox "Duplicate!", vbOKOnly, "Duplicate SO Number Found"
> End If
> End Sub
>
> ______________________________________________________________
>
> If DCount("*", "RMA INFO", "[SO#] = Me.SO_.Value") > 0 Then
> MsgBox "You have entered a value that is already in the
> table!"
> Me.Undo
> End If
>
> ______________________________________________________________
>
|
|
0
|
|
|
|
Reply
|
George
|
6/21/2007 7:18:45 PM
|
|
|
3 Replies
2906 Views
(page loaded in 0.085 seconds)
Similiar Articles: msg for no record found - microsoft.public.access.formscoding ...Cancel = True End If End Sub Or (b) you could use a DLookup to see if the form will have any records ... or could also use: If Dcount("MemberNo ... runtime error '2001' - microsoft.public.access.queries ...RunTime Error '2001' Hi, I am getting " runtime error '2001' you cancelled the previous operation ... Runtime error 2001 - Microsoft Access / VBA The 3rd argument of DLookup ... IIf statement, wildcard to return all records - microsoft.public ...... or "Option2" or "Option3"" and i got an error saying "you > canceled the previous operation ... within the query ... expression - microsoft.public ..... that DLookup ... How can I reference a value from a previous record? - microsoft ...(The previous record would be determined using the ... use a query, but you could also use the DLookup ... MsgBox conMESSAGE, vbExclamation, "Invalid Operation" Cancel ... Runtime Error '2001' You Canceled The Previous Operation ...Runtime Error '2001' You Canceled The Previous Operation ... If Not IsNull(DLookup("ID", "tblCompaints ... DCount(Expr as String, Domain As String ... Access Help and How-to - Microsoft Office "You canceled the ...... control, or query in a DoCmd.RunQuery or a DLookUp or DCount ... 2003 you canceled the previous operation, you cancelled the previous operation access 2003 microsoft dcount ... Cancel previous operation error - dBforumsI keep getting the "You canceled the previous operation" error and I can't tell why. ... I've determined the error occurs whenevery there is a DLookup, DMax, DCount, etc ... Using MS Access: You canceled the previous operation follow up ...Using MS Access /You canceled the previous operation follow up ... The third section of DCount(1,2,3), and other functions like DLookUp(1,2,3), is similar in ... RE: DLookup you cancelled the previous operation> Everytime I run the code it gives me the "You cancelled the previous > operation." ... Cancelled Previous Operation on DLookup or DCount: AJ: Microsoft Access Forms 7/21/2012 6:30:35 AM
|