Home > Forum Home > Automating Data Analysis Tasks > Send variables to MSQuery via entry in Excel cell range? | Share |
Forum Topic | Post Reply Login |
Send Variables To Msquery Via Entry In Excel Cell Range? | Rate this: (3/5 from 1 vote) |
I do a lot of data query with Excel, and am running into projects where it is impractical to continue because of query variables that change. Currently this requires that I open the query, manually chance the variable/criteria, refresh, return to Excel, print, then start over again! Specifically I'm pulling information for sales usage by a specific salesperson and date range. If there are 40 salespersons, this requires editing the MSQuery 40 times to get the data! What I'd like to do is build the Excel report to include an input cell or two (today's date (via formula) and sales ID), have that data pass directly to MSQuery and return the updated data - without having to open MSQuery. Possible? Thanks! | ||
Posted by jwhitwell on |
Replies - Displaying 1 to 10 of 12 | Order Replies By: Most Recent | Chronological | Highest Rated |
Rate this: (3.5/5 from 2 votes) Run-time error '1004' General ODBC Error With the following line highlighted .Refresh BackgroundQuery:=False From google, looks like everyone is looking for a solution to this problem. Can someone please help!? Thanks! | |
Posted by StartingToLoveExcel on |
Rate this: (3/5 from 1 vote) | |
Posted by lauriepass on |
Rate this: (3/5 from 1 vote) VBA Code:
| ||
Posted by lauriepass on |
Rate this: (3/5 from 1 vote) If you setup the query like the above help file says it will prompt you with a message box for the parameters. If you do that once to return results to Excel you can then right click anywhere in the query results and select PARAMETERS then you can select to "Get the value from the following cell." You can also have the query run when that cell's value changes. I'm sure there is a better way of doing all of this but this is what works for me and it will solve the problem you mentioned. | |
Posted by dasaltyone on |
Rate this: (3/5 from 1 vote) | |
Posted by jajknight on |
Rate this: (3/5 from 6 votes) http://www.mrexcel.com/archive2/19400/22013.htm Open your query in the MS Query editor. Change the hard-coded date (or whatever the data-type) to "[Parameter_Name]". When you press enter, you will be prompted to enter a value for the parameter. Return to Excel, right click on your query and select "Parameters". Select the third radio button "Get the value from the following cell" and then enter the cell reference. You can check the box below that to have it auto-refresh when the value of the cell changes. This should work, and is far simpler than coding it into VBA. | |
Posted by KhabaLox on |
Rate this: (3/5 from 1 vote) "Select * from table where field = " & variable wont work because msquery expects single quotes for each value try "Select * from table where field = " & "'" & variable & "'" | |
~ | |
Posted by xluser on |
Rate this: (3/5 from 1 vote) I tried running the code above with just the database definitions changed and i keep getting a 438 error : OBject doesnt support this property or method. I assume this means i'm using a method in a way i shouldn't, as i said i only changed the database definition. I have never used VB before i just had to use it with excel it seems to be the line With ActiveSheet.QueryTables.Add(Connection:=Array("ODBC;DSN=**************;Description=*****************;APP=Microsoft Office XP;DATABASE=*****************;Trusted_Connection=YES"), Destination:=Range("B5").CommandText = Array("SELECT * FROM *****.****.*************, ********.************ WHERE **************='val'")) The *** are obviously datatbase stuff i cant post on the net. Other than that it seems to be the same, any ideas?? | |
Posted by tweedledum on |
Rate this: (3/5 from 6 votes) Excel Spreadsheet:
You can then create a VBA macro which pulls the values in cells C2 and C3 to return sales starting in cell B5. The following example uses the Northwind DNS to get sales from the Order table, so you will have to change the connection, query and other options to suit your own purposes. VBA Code:
To insert the macro, go to Tools >> Macro >> Visual Basic Editor and Insert Module. Once the code has been copied and modified, you can add a button or a graphic to assign the macro to. | ||||||||||||||||||||||||||||||||
Excel Business Forums Administrator | ||||||||||||||||||||||||||||||||
Posted by Excel Helper on |
Rate this: (3/5 from 1 vote) To DSN must be set up (named "Northwind") to connect to an SQL Server with the default database being Northwind. To do this go to Control Panel > Administration Tools > Data Sources (ODBC) and Add an SQL server DSN accordingly. | |
Excel Business Forums Administrator | |
Posted by Excel Helper on |
Displaying page 1 of 2 | Next |
Find relevant Excel templates and add-ins for Send variables to MSQuery via entry in Excel cell range? in the Excel Business Solutions Directory |