Excel: Parametrizing using Microsoft Query - excel

I use Excel as front end to display data from a database. Concretely, I have customer information in a MariaDB database and with sql I extract for each customer
information from the database using Microsoft Query/ODBC:
SELECT name, n_consultation
FROM consultation
WHERE customer_id = 1
So, for each customer I have one Excel workbook with five sheets where each sheet has another sql-query with the same customer.
To create a new Excel workbook I make a copy of the Excel workbook of customer 1, change name of the workbook and in each sheet I change the WHERE part by changing
the customer_id = 1 to customer_id = 2. This I can do quite fast by short cuts (ALT+V, J, etc.).
Having 10 customer and 5 sheets for each workbook I have to do 50 changes and this is feasible. But in case of 100 customer this is not manageable. Is there a
way to use a parameter with Microsoft Query/ODBC?
For example, the queries could be written with:
SELECT name, n_consultation
FROM consultation
WHERE customer_id = #id
and #id can be defined in the first sheet.
If this is not possible I suppose that the only alternative is using VBA.

I propose to change the SQL syntax at Queries & Connection--> Properties --> Definition tab like follows
WHERE customer_id = ?.

Related

Reconciliation between Sharepoint List and monthly excel file uploaded to Sharepoint

I am quite new to power apps and trying to determine the best course of action for my below scenario. I want to identify which users submitted to List A and which haven't based on each new monthly file.
I have a List(List A) on Sharepoint I created where users go in and input information, I want to come up with a list of users who have submitted to this list.
I want to reconcile with this monthly file excel that is dropped into a sharepoint link by another user with updated information. So essentially it would be doing a Vlookup into List A to determine who has submitted a record. .
So what I have done:
Created List B manually (from the excel file dropped)
using Power automate/Flow do a vlookup from List B to A whenever a record is created in A.
I created a column in List B that is not within the standard excel file (Column name Submitted, answers would be either Yes/No based on the vlookup) , Vlookup is something like if A.ProjectID = B.ProjectID then B.Submitted = Yes otherwise No.
Problem:
What are my options to get around the fact this file is uploaded monthly? I dont want to recreate List B each month and have to setup the "Submitted" Column each time. I want this to work in an automated fashion.
Some Questions/Ideas:
Is there a way I can overwrite List B and keep the "Submitted" column each month automatically? It is dropped into a new folder each month on SP. ie "Aug 2021" , "Sept 2021", etc.
Can I do the recon in the sharepoint excel file itself automatically each month? Ie When the excel file is created run a macro to create the new column and do a vlookup?
Can a 3rd List be created as some master tracker page to hold all project status'?
Any ideas or suggestions are welcome. Looking for the best way on how to do this. Thanks
I think you should approach this from PowerAutomate.
I'd start off by creating a flow with a SharePoint trigger to catch when the Excel file is uploaded.
You should then get the content from the Excel with Excel Online / List Rows in a Table
Use 'Apply to Each' to loop over each user in the table. Inside the loop do the lookup.
Write back the result to the Excel with Excel Online / Update a Row action.
I'd recommend you create a separate thread for the project master list problem and elaborate your goals thereto.

Filter Access Table based on External List

I have a table called "Inventory", which contains all the "Items" (physical parts, components).
I have another table, called "Products", where the main products are listed.
A third table is "Manufacturing Orders".
Every time a new manufacturing order is in production i'd like to get this two effects:
The quantity in stock for the selected Products increase
The quantity of the items which made the Product up decrease of their specific units.
Of course to do this i need a BOM.
I'm trying to figure out the most efficient way to generate a BOM.
The solution I've thought about so far is the one as follow:
Every time there is a new Manufacturing Order, filter the Inventory table based on an External list (on Excel), and decrease the qnt just for the items available in the "Filtering list".
I'm wondering if there is some function in Access which allows this or i do need VBA.
Also, if there is a more quick and efficient solution.
Note: i decided not to create the bom as tables to keep the db more clean.
Thanks in advance
I would first determine from which application are you controlling this update; from within Access retrieving the data from Excel, or within Excel updating the tables in Access?
If you are within Access you could pull the data into a record set in a manner such as Query Excel worksheet in MS-Access VBA and then using the rs2.field(***).value to build a Access-SQL UPDATE string to update the table. This could be placed in a form that drives the VBA code. Note that within the referenced hyperlink there is a function fncOpenFile. This is most likely a file dialog procedure to retrieve the filename. A similar function is this:
Private Function GetFileName() As String
Dim FO As Object 'file object
Set FO = Application.FileDialog(3)
With FO
.allowMultiSelect = False
.show
GetFileName = .SelectedItems.Item(1)
End With
End Function

Write from Excel to Access multicolumn combobox field using VBA

I have an Access file with two tables: users & products. Users keeps a list of who can write to the Access file (fields like userID, systemID, name). Products keeps a list of product attributes including who made the last update to the record. The last update field is a combobox with two columns: userID (bound to this), name (displays this due to column widths of 0";2").
I also have an Excel file, named simulator. Using VBA, the simulator reads from the products table, uses assorted prediction algorithms to simulate the product's future, then writes the predictions back to Access.
When Excel writes back to a product's record, I'd like to record the last update author to be simulator. Assuming this user exists (userID=100, name=Simulator, say), how do I do this?
I currently have
' Open Access database, get products table, get product record
connection.Open ...
products.Open "Products", connection, ...
products.Filter = "ProductID = " & productNumber
' Update record
products("LastUpdateAuthor") = "100; Simulator"
products.Update
products.Close
And this writes "100; Simulator" to the correct field. How do I get it to recognize that 100 is the bound column and Simulator is the second column?
Should only save the UserID into LastUpdateAuthor field. Then multi-column combobox RowSource should be an SQL statement of Users table in order to retrieve and view the related UserName. So have a record in Users with UserID 100 and name Simulator, then still just save the UserID.
As long as the RowSourceType is Table/Query, it will see the 100; Simulator value as a single string from the LastUpdateAuthor field. Can set combobox RowSourceType as ValueList then use code manipulating recordset and Add method to load the LastUpdateAuthor data to the RowSource and the semi-colon will be recognized as column separator. However, if you do as described in first paragraph, this should not be necessary.

Adaptable Hyperlink between documents

I'm looking for a way to create a hyperlink on a tracking sheet that will recognize a part of a document name to link to.
for example if I have a list of forms that needs to be audited (numbered 1 thru 10) in one column of a sheet that refer to docmuents that are saved in another folder, can I use a formula that will recognize the name of the forms to be audited as they are created and automatically link them?
It would like this (in an excel format)
(folder 1, excel workbook1)
Column 1 -- Column 2
Doc 1 -- Mr. Auditor
Doc 2 -- Mrs. Auditor
Doc 3 -- Dr. Auditor
(folder 2, individual workbooks)
Financial Doc 1.xlxs
Financial Doc 2.xlxs
Financial Doc 3.xlxs
.
The tracking sheet will be initially be numbered 1-80 regardless of how many docs exist in the other folder, but as the Financial Docs are added if they keep a consistant naming convention I would like their respective position in column 1 of the tracking sheet to automatically link to that doc.
If this is possible, or if it requires a different method I would be eager to learn it. I would be able to use this to organise a large amount of information on simple sheets.
Thank you all.

COGNOS report for a simple sub query and join Query

Here is my query. I am new to Cognos and using Cognos 10. And I am having a bit difficulty in developing a report which uses a Sub Query and an Inner Join Query.
1.
SELECT ID, BATCH_DT, LOCIT FROM AOI.TEMP_BRICK
WHERE BATCH_DT < (SELECT MAX(DATE) FROM CALENDAR)
2.
SELECT A.ID, B.SAL FROM TABLE as A LEFT OUTER JOIN TABLE as B
WHERE A.ID=B.ID
First, you must understand that Cognos generates its own SQL. In order for it to do that, you must define relationships between tables in Cognos Framework Manager. Once that is done your report has 3 major parts, The Report Page(s), the Prompt Page(s) and the Query(s).
a.) Setup the CALENDAR and AOI.TEMP_BRICK tables in Cognos. You may want to define a relationship between TEMP_BRICK.BATCH_DT and CALENDAR.DATE (assuming your calendar has date records for every date that may be present in TEMP_BRICK).
b.) Next you would create a new List Report. You would grab your ID, BATCH_DT and DATE fields into the list. (Date would come from the calendar if you decided to link the two tables in step A, otherwise you use the BATCH_DT field in TEMP_BRICK.)
c.) You would open the Query pages and see that Cognos has already created one query, called Query1. You need to create a new query (we will call it qryMaxDate). That query would have one element, 'DATE' from CALENDAR. On the properties of the 'DATE' field in Data Items, you would chagne the 'Agregate Function' from None to 'Maximum'.
d.) Now edit your Query1, add a Filter on the Date from that query. In the Expression Definition, select the Queries tab and drag the 'DATE' field from your qryMaxDate. Should look something like this [Batch Date] = [qryMaxDate].[Date]
e.) You are done! Run the report. in this case, the user running the report is giving no input, so no Prompt page is necessary.
a.) Setup Table A and B in the Framework Manager. You need to define a relationship between Table A and B in Framework Manager via a Star Schema (define A.ID = B.ID and specify 1 to n, or n to 1).
b.) Create a new report and simply drag in elements from table a and table b. Their relationship is already defined in Framework manager, so there is no need to re-define it while writing reports.
Your second example is a great demonstration of the power of BI programs like Cognos. Report Authors dont need to fully understand the ways that two tables are joined... they simply pull out elements from each table and they work, as the relationships are already defined in the Framework.

Resources