deletion qry - VBA

tuktuk

Well-known Member
Joined
Nov 13, 2006
Messages
856
i need to grab the MinOfPayDate form a tbl.....and us that MinOfPayDate as the parameter for a deletion qry. more specifically ">=MinOfPayDate "

am i making the vba for that function too difficult:

here is my attempt:
Code:
Function DeleteNecessaryData()

Dim rsDeleteDate As Recordset
Dim x As Integer
Dim SQLT As String
Dim strDate As String

Dim flds As DAO.Fields
Dim fld As DAO.Field

Set rsDeleteDate = CurrentDb.OpenRecordset("MinDate")

'this defines the desired field in the qry to be the parameter
Set flds = rsDeleteDate.Fields
Set fld = flds("MinOfPayDate")

With rsDeleteDate
    .MoveFirst
    
Do While Not .EOF
 strDate = fld

Const QRY_APPEND = "Delete30days"
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb
'this is the delete query
Set qd = db.QueryDefs("Delete30days")
qd.Parameters(0) = strDate
qd.Execute

    rsDeleteDate.MoveNext
    
Loop
  End With

Set rsDeleteDate = Nothing
'strPayCountry = Nothing

Set fld = Nothing
Set flds = Nothing

End Function

i've yet to be able to test but i'm sure there is a better way....i morphed this from the vba used to append data with a parameter

tuk
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
What are the fields in both of these tables, and if possible some relevant sample data? In plain English, what is the desired result (e.g., ... Delete all records from Table X where due date is less than the x in Table Y ... ). I suspect there's no need for vba at all, unless it is merely to run the sql command.
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top