Help with coding a delete button!

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Because I have my same list box on 2 seperate forms is there any way I can
add these 2 Requery codes to my delete button code that is on my Invoice
form which is selected from either frmMain or frmModify..........Thanks for
any Help....Bob

CurrentProject.Connection.Execute "DELETE * FROM tblAdditionCharge WHERE
InvoiceID=" & Nz(val(tbInvoiceID.value), 0)
CurrentProject.Connection.Execute "DELETE * FROM tblInvoice
WHERE InvoiceID=" & Nz(val(tbInvoiceID.value), 0)

Set recInvoice = Nothing
End If

DoCmd.Close acForm, Me.Name
Forms!frmModify!lstModify.Requery
Forms!frmMain!lstModify.Requery

End If
End Sub
 
As long as those two forms are open.
Does what you have not work? If not what is the error. Other than the
portion of code I can't see, I don't see what's wrong with what you
have (as far as the requerying goes).
 
storrboy said:
As long as those two forms are open.
Does what you have not work? If not what is the error. Other than the
portion of code I can't see, I don't see what's wrong with what you
have (as far as the requerying goes).
I am getting the Error " Cant find frm Modify" No matter which order I put
them in my code,when I try to delete from list in frmMain I am getting that
error, but deleting from frmModify it is correct no errors...Thanks Bob
 
I am getting the Error " Cant find frm Modify" No matter which order I put
them in my code,when I try to delete from list in frmMain I am getting that
error, but deleting from frmModify it is correct no errors...Thanks Bob


But you're not telling me that they are both open when this runs.
When these three lines are run...

DoCmd.Close acForm, Me.Name
Forms!frmModify!lstModify.Requery
Forms!frmMain!lstModify.Requery

....what is the name of the form that the first line refers to? If you
are closing frmModify or frmMain, then one of the two requery lines
will fail. I guess the simplest thing to do is to add a Resume Next
line so that if one of the forms is not open, then no error will
occur.

On Error Resume Next
DoCmd.Close acForm, Me.Name
Forms!frmModify!lstModify.Requery
Forms!frmMain!lstModify.Requery

But if this same block of code runs from either Modify or Main, then
you *are* closing one of them before requerying, and you can't requery
a control that is not open. Move the DoCmd line to be after the
requery lines.
 
storrboy said:
But you're not telling me that they are both open when this runs.
When these three lines are run...

DoCmd.Close acForm, Me.Name
Forms!frmModify!lstModify.Requery
Forms!frmMain!lstModify.Requery

...what is the name of the form that the first line refers to? If you
are closing frmModify or frmMain, then one of the two requery lines
will fail. I guess the simplest thing to do is to add a Resume Next
line so that if one of the forms is not open, then no error will
occur.

On Error Resume Next
DoCmd.Close acForm, Me.Name
Forms!frmModify!lstModify.Requery
Forms!frmMain!lstModify.Requery

But if this same block of code runs from either Modify or Main, then
you *are* closing one of them before requerying, and you can't requery
a control that is not open. Move the DoCmd line to be after the
requery lines.

Thanks Storrboy , Worked Brilliantly, thanks for your effort.....Bob :)
Set recInvoice = Nothing
End If
On Error Resume Next
DoCmd.Close acForm, Me.Name
Forms!frmModify!lstModify.Requery
Forms!frmMain!lstModify.Requery


End If
End Sub
 
Back
Top