Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

Excel VBA needs to run SQL query

I have an Excel spreadsheet which gets its data from an external data source (a SQL database).  The SQL query used pulls all data from a table which is within a date range.  At the moment this date range is assigned by manually updating the query.

Once the data is on the spreadsheet, I have a macro which updates the sheet, and refreshes the database query thus presenting up-to-date information.

I'd like to use VBA to prompt the user for a date range, so that they don't get a chance to edit the whole query.  The dates they enter would be inserted into the SQL query and then run against the database.

Any ideas?

Danny

0
SquareOneResources
Asked:
SquareOneResources
  • 2
1 Solution
 
ampapaCommented:
You could use a standard input box then modify your query with the users input. You might also check the users input after it is entered.

dim BgnDte, EndDte

BgnDte = Application.InputBox(prompt:="Enter Beginning Date:", Title:="Beginning Date", Left:=300, Top:=50, Type:=2)

EndDte = Application.InputBox(prompt:="Enter Ending date:", Title:="Ending Date", Left:=300, Top:=50, Type:=2)

ampapa,
0
 
ampapaCommented:
A grade of "C"?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now