Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2007, 10:07 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default vb DLOOKUP function and dialog box error

Hi.
I'm hoping you can help me; I'm rather new to VB, and like what it can do for you. Makes a tool so much more powerful than without.

I'm running into an error; (learning process.) The error is:
                     Run-time error '2001': You canceled the previous operation

I'm not sure what that means; tried googling it, nothing came up. Here's my code:
__________________________________________________ _____________

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim varDUPPO As Variant

If Me.NewRecord Then

    varDUPPO = DLookup("[Reseller Account Number]", "[dup PO check]", "[Reseller Account Number] = '" & Me![Reseller Account Number] & "' AND [Reseller PO#] = '" & Me![Reseller PO#] & "' AND [End User Name] = " & Me![End User Name] & " AND [Amount] = " & Me![Amount])

If Not IsNull(varDUPPO) Then

            If MsgBox("This record already exists." & _
                        "Cancel this new entry and review the previous entry?", _
                        vbQuestion + vbYesNo, _
                        "Duplicate Entry Found") _
                        = vbYes _
            Then
                Cancel = True
                Me.Undo
                Me.Recordset.FindFirst "[Reseller PO#]='" & varDUPPO & "'"

End If

End If

End If

End Sub
__________________________________________________ ____

Can anyone help me please? Thank you.




bluezcruizer
 
Old January 15th, 2007, 02:17 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This looks more like an Access error than an VB6 error.

Woody Z
http://www.learntoprogramnow.com
 
Old January 18th, 2007, 04:25 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I think you will find that your life is a happier place to be if you pay more attention to formatting in the code you write. It certainly will make assessing your code easier if you format that which you post here. If you put the word "code" between a couple of square brackets before your code, and the string "/code" between a couple of square brackets at the end of your code, it will be rendered in a fixed font here, and will preserve your indentation. To wit:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

    Dim varDUPPO As Variant

    If Me.NewRecord Then

        varDUPPO = DLookup("[Reseller Account Number]", _
                           "[dup PO check]", _
                           "[Reseller Account Number] = '" & Me![Reseller Account Number] & "' AND " & _
                           "[Reseller PO#] = '" & Me![Reseller PO#] & "' AND " & _
                           "[End User Name] = " & Me![End User Name] & " AND " & _
                           "[Amount] = " & Me![Amount])

        If Not IsNull(varDUPPO) Then

            If MsgBox("This record already exists." & _
                      "Cancel this new entry and review the previous entry?", _
                      vbQuestion + vbYesNo, _
                      "Duplicate Entry Found") = vbYes Then

                Cancel = True
                Me.Undo
                Me.Recordset.FindFirst "[Reseller PO#]='" & varDUPPO & "'"
            End If
        End If

    End If

End Sub
Please indicate which line raises the error. I think it is possible that the Cancel = True and the Me.Undo represent redundancy.

Before this routine is called, Access generates a boolean variable, and passes a reference to that variable into the variable called Cancel. When the routine is done, before Access does anything more, it checks the value of that Boolean. If it has been changed to True, the update does not take place. But perhaps the Undo has exterminated the updating process already, so that the Cancel’s value makes access attempt to do something that has already been done. (I'm guessing here; I forget exactly what .Undo does.) This would seem to be in keeping with the message you are receiving.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Dialog Box peace2007 Ajax 1 September 26th, 2007 08:26 AM
Help - Dlookup function kk_sg Access VBA 3 August 23rd, 2006 11:30 AM
insert dialog box in a dialog box BurhanKhan Visual C++ 7 June 1st, 2004 07:53 PM
Dlookup function giving Type Mismatch error Ron V Access 2 May 19th, 2004 01:31 PM
Error trying to call Oracle function in VB.NET lou_1 Pro VB.NET 2002/2003 0 January 13th, 2004 06:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.