Deleting records

D

Dudley

I would like to delete all records in my invoicing database where the last
invoiced amount is zero, and I found found the following code which looks as
if it can be adapted for this:

Function LastInvoiceAmount(Client As String) As Currency
On Error GoTo Err_LastInvoiceAmount

Dim LastIN As Long

LastIN = Nz(DMax("[Invoice Number]", "Invoices", _
"[Customer Code] ='" & Client & "'"), 0)

End_LastInvoiceAmount:
If LastIN = 0 Then
LastInvoiceAmount = 0
Else
LastInvoiceAmount = InvoicePriceIncVAT(LastIN)
End If
Exit Function

Err_LastInvoiceAmount:
MsgBox "Error " & Err.Number & ": " & _
Err.Descriptiong
Resume End_LastInvoiceAmount

End Function

Can anyone tell me how I can delete all records where LastIN = 0?

Thanks very much for any help.

Dudley
 
D

Dorian

When deleting always first create a query to select those records to verify
the right ones will be deleted
SELECT * FROM [tablename] WHERE LastIN = 0
then when verified, change to
DELETE * FROM [tablename] WHERE LastIN = 0

full code is:
CurrentProject.Connection.Execute "DELETE * FROM [tablename] WHERE LastIN =
0",,adExecuteNoRecords

-Dorian
 
D

Dudley

Thanks very much for your help. I wasn't quite sure how to do this, but I
tried creating a public function and then calling it with a macro from my
Clients form, and I get a message compile error, variable not defined, for
AdExecuteNoRecords. Can you advise please.

Dudley

Dorian said:
When deleting always first create a query to select those records to verify
the right ones will be deleted
SELECT * FROM [tablename] WHERE LastIN = 0
then when verified, change to
DELETE * FROM [tablename] WHERE LastIN = 0

full code is:
CurrentProject.Connection.Execute "DELETE * FROM [tablename] WHERE LastIN =
0",,adExecuteNoRecords

-Dorian


Dudley said:
I would like to delete all records in my invoicing database where the last
invoiced amount is zero, and I found found the following code which looks as
if it can be adapted for this:

Function LastInvoiceAmount(Client As String) As Currency
On Error GoTo Err_LastInvoiceAmount

Dim LastIN As Long

LastIN = Nz(DMax("[Invoice Number]", "Invoices", _
"[Customer Code] ='" & Client & "'"), 0)

End_LastInvoiceAmount:
If LastIN = 0 Then
LastInvoiceAmount = 0
Else
LastInvoiceAmount = InvoicePriceIncVAT(LastIN)
End If
Exit Function

Err_LastInvoiceAmount:
MsgBox "Error " & Err.Number & ": " & _
Err.Descriptiong
Resume End_LastInvoiceAmount

End Function

Can anyone tell me how I can delete all records where LastIN = 0?

Thanks very much for any help.

Dudley
 

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

Top