How to change declared variable in OLE DB Query by editing a cell from Excel? - excel

We have different connections and different pivot tables connected to them in our Excel sheet and we don't want to edit them each time using data-> properties-> definitions (editing) to get them updated.
It would be much greater if we had just cells to edit
For example:
And write someting like this:
In my case i get an error of course but maybe you know how avoid it?

Related

Editing data through a filter in Excel

I have a large imported .csv as a (Query) table in an Excel workbook. I'd like for users of the workbook to be able to select a small subset of that data and update some values without having to play around with filters on the table.
To that end, I've set up a FILTER on a separate sheet, something like:
=FILTER(my_table[some_column], my_table[id_column]="some value")
That pulls in values from the relevant column and displays them.
My question: is there any way to allow users to edit the values retrieved with the FILTER, so that the changes are reflected in the original table? Attempting to edit such a value now just edits the underlying field, causing the FILTER to update and display #SPILL! (which makes sense, since there is not enough free space to render the result).
I've looked at options for FILTER, and thought about writing some custom VBA code to do what FILTER does "manually", and then watch the sheet for updates in that range - but that seems like a lot of coding to do something I would imagine is more commonly needed?
Am I going to have to code this up in VBA? Or is there some alternative approach to using the FILTER?

Excel 2010 check cells in a row contain data before the Selection Change fires

I have an Excel 2010 data table which is driven by a query from MSSQL. The underlying query changes depending upon what options the user selects in the Excel workbook. I'm okay with changing the query and pulling the data.
After the data has been selected multiple users will be able to edit and append data to the Excel table and these changes will post back to the SQL database table. Due to the database table structure some of these cells within a given row are mandatory before any data can be inserted into MSSQL and/or potentially updated.
So what I'm trying to achieve is checks on whether certain columns in a row are blank after a cell is edited (I can do this via Worksheet Change) and also before they move off that row so I can bring up a message if all mandatory columns haven't been entered. I can't see any events that fire before Selection Change. My only thoughts on a workaround is to have a global variable row marker that is updated on Selection Change, i.e. it will store the previous row number. I can't use Excel's standard data validation functionality looking at blank cells because although this is fine for a currently correctly populated row that is being edited, inserting new rows or appending directly to the bottom of the table will constantly error as all those mandatory columns will, of course, be blank. Currently I am using conditional formatting to at least highlight columns/cells that require input although this doesn't force users to actually do it. Data cannot be stored within MSSQL until these columns contain data so if they don't fill them in and refresh the table for whatever reason, whatever they have entered will be lost. Obviously this is bad, m'kay. I am concerned about both the Worksheet Change and Selection Change events constantly firing and how that will affect workbook performance.
Any suggestions would be appreciated. Maybe I'm going about this all wrong so any ideas to make this more efficient would also be well received. The user base do not want to see UserForms or MS Access even though it would make this activity very easy. They are too used to the look and feel of Excel sheets.
your best way is to copy the table into 2d array or some other data structure in memory such as dictionary or collection. and than manage each change in memory. this one is very efficient but requires a lot of code. with excel the only problem you have is the key the rest is vlookup and true false questions. vlookup will find the original value and then you have current data + previous data + the logic... is the new data ok?

Connecting different databases in Excel

Let's say I have an Access database, "ADB", and an Excel workbook, "EWB".
ADB has a table called "ATable" which contains columns including a column called "A_ID"
EWB has a worksheet called "EWorksheet" which contains columns "E_ID" and "ECol"
Now, I want to know how I can create an Excel worksheet that combines ATable.A_ID from ADB and EWorksheet.ECol from EWB, where if A_ID = E_ID then return ECol.
So in SQL, it should look something like this:
SELECT ATable.A_ID, EWorksheet.ECol
FROM ADB.ATable, EWB.EWorksheet
WHERE ATable.A_ID = EWorksheet.ECol
Of course I want the data to be dynamic, so that data will be updated when refreshed.
You need something called PowerQuery, in Excel 2016 comes by default. In previous versions you will have to install it.
Once you have it, it´s pretty straightforward. Select a connection as seen below selecting an Access database or an Excel workbook.
Once you have both queries loaded in PowerQuery you need to merge them through the column you specified, and that will make the join for you.
What PowerQuery does is record a set of steps such as connecting to an Access database or merging 2 tables. Those steps are saved within the file, so when you click RefreshAll in Excel it will reproduce those same steps you specified and bring you the latest data.

Import a single value from Access into Excel (without the column heading)

I would love to know how to import a single value from my Access database into an Excel cell.
Alternatively removing the header would be a good start.
The query
SELECT SUM(DEMANDS) AS TOTAL FROM [DB PROD]
gives me a header named TOTAL and, right below it, the sum I'm interested in. I use this query from within Excel (Data > Get External Data > From Access). How can I only get the sum in a single Excel cell?
One way to accomplish your goal would be to put your existing query on a different Sheet, say Sheet2, so the column header appears in Sheet2!A1 and the value appears in Sheet2!A2. Then reference the value cell from elsewhere in the Excel document. (The formula will look something like =Table_test.accdb[TOTAL].)
If you had several queries you could presumably keep them together (side by side) on the same sheet. You could also hide the query sheet so the "magic" would be more transparent to the user.
I am not sure I understand what you are doing, but, in order to read Access data from Excel, you need to do the following:
programmaticaly open a connexion in your Excel code, pointing to your
access database (let's say an ADO connexion for example)
then execute your 'SELECT' through this connection, using the ADODB.command object. That will return the requested value
another option would be to open a local recordset in Excel,based on your SQL intruction, and read the value.
Then do not forget to close your connexion

Excel Show Data Based on user Choice

Excel 2007: I get my data from Access tables the Excel sheet is called "Data". My Excel report cells are populated by linking to those data cells(=Data!A1) and some report cells have simple code. But my question is this; my report needs to specify one record. Example: Data record 1: Name=Joe, Birth=7/29/62, Country=USA: record 2: Name=Sam, Birth=4/13/74, Country=China... How do we control the report display to a specific record? If I add a DropDown or ListBox, how do we make only the records for the name picked show in the report. Is there a way to put the code behind the listbox, or should I scrap the list and create a macro, what is the best way for a user to pick the data to be displayed on the report? Suggestions please...
There are two approaches I would use.
When you embed a query object in Excel (which is, I assume, how you are fetching the data from Access) you have the ability to edit that query in the little Query Editor tool.
You can add criteria to that query in this tool - there's a filter icon, you select let's say the Name column, and then type "Sam" in the box below, and that will produce a SQL statement that now includes "Where Name = 'Same'" at the end.
However, that's not that helpful for reporting, since most likely we want the name to be a parameter passed in from the Excel sheet itself. If in the criteria box, you type "[enter name]" instead of "Sam", the square brackets tell the Query tool that this is a user supplied parameter. When you run the query from the tool now you get a pop up box asking you each time for the name.
Now when you exit the query tool and return to Excel, you can edit the Query Parameters for that embedded query object. The parameter you made (name) is there, and it can either take on a static value, prompt the user, or take the contents of a cell. You can even set a flag to refresh the query when the cell contents change.
The other approach goes a little further and manipulates the query object in some VBA code. If you need to do some heavier lifting, or other logic, for example, and you don't want to deal with writing it all out as spreadsheet formulas. An easy way to do that is to drop in a button on the report sheet and have the VBA code start on that button's click event.

Resources