Run Query on Subform Using VBA Macro Button

Joined
Jul 18, 2014
Messages
3
Reaction score
0
I have the following issue. I have a form with a subform that gets data from a table.

I have different queries set up to provide filtered results based on the individual queries.

How can I set macro buttons up in the main form that would allow an existing query to filter the subform and provide the data results of that query in the subform?


I tried the below process I Googled and this did not work at all.

Private Sub RecordsetFromSQL_DAO_Click()
' Comments: Browse a query and display its fields in the Immediate Window using DAO
Const cstrQueryName = "qrySelect_TaskDueDates_AllDueDates_EarlyOnTime"
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
' Open pointer to current database
Set dbs = CurrentDb
' Open recordset on saved query
Set rst = dbs.OpenRecordset(cstrQueryName)
' Display data from one record and move to the next record until finished
Do While Not rst.EOF
Debug.Print "Position: " & rst![Position] & " Category: " & rst![Category] & " Due Date: " & rst![DueDate] & " Task: " & rst![Task] & " SubTask: " & rst![SubTask] & " Start Date: " & rst![StartDate] & " Completion Date: " & rst![CompletionDate] & " Comments: " & rst![Comments]
rst.MoveNext
Loop
rst.Close
dbs.Close
End Sub

Any assistance would be greatly appreciated!!
 
Joined
Jul 18, 2014
Messages
3
Reaction score
0
Update to my Post:

Perhaps this will help to explain what I am trying to do using a macro button on a main form to filter data in my subform.


VBA Macro process for first button:
In my subform I have a [DueDate] field.

I need to be able to filter between a date range within the [CompletionDate] field in my subform.

The user should click on the button on my main form.

A pop-up window will appear requesting the user to enter the begining [CompletionDate] value desired and the last [CompletionDate] value desired.

The results will filter all records between these two dates in the subform.


VBA Macro process for second button:
In my subform I have a [DueDate] field and want to find processes that are late.


I need to filter records where the [DueDate] < Date() AND [CompletionDate] = NULL

AND

I also need to filter records where the [CompletionDate] > [DueDate] in the same VBA macro function.
 

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