Excel VBA. Changing a query critera via ADO

PTP86

Board Regular
Joined
Nov 7, 2009
Messages
86
Hi

The 2nd of today's questions.

I've got an Excel macro that runs lots of queries in Access and imports the results to the spreadsheet.
I've avoided writing complex SQL in VBA by building the queires in Access and then writing a simple select query in the VBA.

For 1 of the queries, I'd like the user to be able to specify part of the criteria in Excel and then the macro adjust the criteria accordingly (or another workaround)
There's 1 workaround I've thought of but it doesn't help if the user doesn't want that field in the criteria

e.g. Pretend there's an Access table that has the number of sales of each fruit on each day of the week.
The spreadsheet wants to give the user the option of choosing to import the sales for each fruit on just 1 day of the week (i.e. a criteria for [Day] would be set at say Monday), or import the sales for each fruit on each day (i.e. there would be no criteria for the [Day] field).

Is there a way of editing the query to remove the criteria from the [Day] field?


I know how to edit tables from within VBA so have thought about the workaround of having a Criteria table with a [Day] field and it is joined as part of the other query, and the VBA can edit the entry in the [Day] field. However, this doesn't solve the problem when the user is wanting there to be no criteria for the [Day] field.


Could anyone tell me how to edit a query from within Excel VBA or another work around?


Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Bumping this question back, plus condensing it a bit as no answer yet:

Using an ADO connection, is there a way of changing an Access query's criteria from within an Excel macro?


Thanks
 
Upvote 0

Forum statistics

Threads
1,221,574
Messages
6,160,602
Members
451,657
Latest member
Ang24

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