Help with coding a delete button!

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
 
S

storrboy

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).
 
B

Bob

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
 
S

storrboy

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.
 
B

Bob

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

No Message box to show! 1
Requery Problem 1
Intellisoft Problem! 8
Ok This one is Tuff 3
One Control for 2 codes 1
Adding a CC to email code! 7
Enter Date on Emailing 6
Emailing Question from my DB 2

Top