keep gettin an error

Neo

Registered User.
Local time
Today, 19:15
Joined
Mar 5, 2003
Messages
42
I keep getting the error 2467 the expression you have entered refers to an object that is closed"

how do fix this

thanks


Private Sub CmdDelete_Click()


If IsNull(Me.CustomerNo) = True Then
If MsgBox("Press Yes to start a new order, Press No to go back to the Main Menu", vbYesNo) = vbYes Then
Me.CustomerNo.SetFocus
Me.CustomerNo.Dropdown

Else
DoCmd.OpenForm "frmMainMenu"
DoCmd.Close acForm, "frmMainOrder"
End If
End If


If IsNull(Me.CustomerNo) = False Then
If MsgBox("Press Yes to start a new order, Press No to go back to the Main Menu", vbYesNo) = vbYes Then
Me.Refresh
Dim strSQL1 As String
strSQL1 = "Delete* from tblInvoices Where InvoiceNo = " & CStr([InvoiceNo]) & ""
DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL1)
DoCmd.SetWarnings True
Else
DoCmd.OpenForm "frmMainMenu"
DoCmd.Close acForm, "frmMainOrder"


End If
End If


End Sub
 
Neo said:
Code:
Private Sub CmdDelete_Click()

   
     If IsNull(Me.CustomerNo) = True Then
     If MsgBox("Press Yes to start a new order, Press No to go back to the Main Menu", vbYesNo) = vbYes Then
        Me.CustomerNo.SetFocus
        Me.CustomerNo.Dropdown
     
     Else
        [b]DoCmd.OpenForm "frmMainMenu"
        DoCmd.Close acForm, "frmMainOrder"[/b]
     End If
     End If
     
     
     [i]If IsNull(Me.CustomerNo) = False Then[/i]
     If MsgBox("Press Yes to start a new order, Press No to go back to the Main Menu", vbYesNo) = vbYes Then
        Me.Refresh
    Dim strSQL1 As String
        strSQL1 = "Delete* from tblInvoices Where InvoiceNo =  " & CStr([InvoiceNo]) & ""
        DoCmd.SetWarnings False
        DoCmd.RunSQL (strSQL1)
        DoCmd.SetWarnings True
    Else
        DoCmd.OpenForm "frmMainMenu"
        DoCmd.Close acForm, "frmMainOrder"

    
End If
End If

    
End Sub

I'm guessing that the code highlights the line I've italicised - your problem is that if the user clicks No on the initial message box you are closing the form and then referencing the customer textbox on the closed form.

If the form is closed and you don't want the code to continue then put an Exit Sub statement at the correct point.
 
Neo said:
strSQL1 = "Delete* from tblInvoices Where InvoiceNo = " & CStr([InvoiceNo]) & ""

I'd worry about fixing that line too as you are changin a number to a string but have not fixed your inverted commas properly.

strSQL1 = "Delete * FROM tblInvoices WHERE InvoiceNo = """ & CStr([InvoiceNo]) & """"

Why are you converting the [InvoiceNo] to a string?
 
Re: Re: keep gettin an error

I am not sure I was shown the code by some one on this forum ]
never realised.

to keep as an interger I just user " & InvoiceNo

Don't I ?
 
Re: Re: Re: keep gettin an error

peterbowles said:
to keep as an interger I just user " & InvoiceNo

Don't I ?

Yep!
 

Users who are viewing this thread

Back
Top Bottom