Reading connection Last Refresh date - vba

When I hover over a Power Query connection in Queries and Connection menu, I can see short preview of data, list of columns, date of last refresh, load state, source of data and quick menu with view/edit and remove buttons.
Is there a way to retrieve this date of last refresh? Preferably I'd like to write a funtion that would take name of a query as input and output that date.
I've found DataFeedConnection.RefreshDate property but it does not seem to apply to a power query connection (error 1004)

Related

Web Scrape Daily Treasury Rates

I have tried to write some VBA that scrapes a table from the URL below. I would like to create a macro that pulls in the data on a daily basis. Any help is much appreciated. Thank you
https://home.treasury.gov/resource-center/data-chart-center/interest-rates/TextView?type=daily_treasury_yield_curve&field_tdr_date_value_month=202212
I am having problems understanding HTML and the elements function.
I know you want to scrape that table on the treasury page, but it just has daily values of rates for each maturity duration (2yr, 5yr, etc.). These same rates are published every day in their XML feed.
The XML feed is meant to be consumed and parsed by computer code, while the HTML on that page is NOT meant to be parsed by "screen-scrapers".
If your macro pulled in the data from their XML feed every day instead, and you kept a table/log/whatever of each day's rates, after two weeks, you'd have the exact same data as the treasury HTML table, but NOT have all the headaches of trying to parse HTML and always worrying about your code breaking if their HTML layout changes.
Would this later approach work for you?
Update: Eric Salazar's answer reminded me of something. I don't know if you're using Excel VBA, or some other Office app, but if you ARE using Excel, you can use the "'Data Menu'->Get Data->From Other Sources->From Web" feature to import that treasury table into an Excel table. Simply copy the URL of that page, paste it into the URL field of the first dialog that pops up (keep type as "Basic"), click OK, click "Table 0" under Display Options of the next ("Navigator") dialog, and lastly click "Load". By default it will create a table in the current worksheet at the currently selected cell. It will contain all the columns of what's on the treasury page and a few more columns that will be filled with "N/A" (not sure where Excel is getting the N/A field names from). You can get rid of those fields by going into the Power Query Designer before importing the data (instead of clicking "Load" in the previous "Navigator" dialog, click "Transform Data" instead. This will open up the "Power Query Editor" and you'll see a table editor in the main window. Select the column headers you don't want to end up in the table and hit the "Del" key (or right-click and choose "Remove Columns"). The selected columns will now be gone. Now click "Close and Load" in the upper-left corner of the Power Query Editor window.
And like magic, Excel will create a new table on your current worksheet with the data contained on that treasury page. You can then access the table with regular VBA code to refresh and read the values.

using excel, query SQL for specific tags in a table for a given date range

using excel 2013 I need to create a search of a SQL tbl on network SQL server for a specific tag and within a given date range. for instance: the tbl has every make of Chevy made since 1990 and the units sold each day. an example, search for corvette with a date range of 1Jul2017 to 31Jul2017. the result would show up how many corvettes were sold for each day in July of 2017 and I will need to have the total sold for entire month of July.
this in important: I only want them to access the data NOT be able to make changes to database
I can do this in SQL no problem, but I have to do this so someone who does not have access to the SQL database can use this query and get the information they need. the eventual goal is to have an Access frontend for this.
edit: I am no expert in either Excel or SQL but know enough to get some things done. one of the many hats I wear . . .
thanks,
In Excel, Data tab, New Query, From Database, pick the type of database, add connection info, click Advanced options, put your query in the SQL statement window, hit OK, hit Load. Now you have SQL results in a spreadsheet. If you want them to update regularly, go to Data tab again, Connections, select the connection you just made from the list, click Properties, and set it to refresh every hour, or when opening the file, or whatever makes sense to you.
This will only work for users that have permissions to the database. If you need it to be more secure (not hold data in the spreadsheet at all, but only access it from the database), in the connections properties click Refresh data when opening the file, then click Remove data from the external data range before saving the workbook.

Excel SQL import - date format not appearing and time format auto-change. Annoying

I'm working on a Excel application that will obtain data from my Entry form and import it into a Display sheet, both in separate worksheets.
The Entry form has a table to key in data via a combination of manual key-in, dropdown lists and vlookup functions. This table is then defined as EntryTable..
In the Summary form there is an SQL statement (SQL1) used to import the data from Entry to Display.
However every time I click the button, the Entry Date will not appear, and the Time changes its format to include date and time.
What's more for some reason the time format in Entry also changes as well. To add insult to injury.
Basically my question here is:
Why was Entry Date omitted in the search even though the SQL specifically stated to select all?
Why does the time always have to add a date in the format every time I try to import?
If anyone know what the issue is, please share with me. Because I'm all out of ideas and I'm losing my patience.

How do I get the index of each record displayed on crystal reports?

I'm developing winform application using vb.net. I use crystal report in my application. Now i need to store the index of each record that is displaying in current report into database. Then i create another report which displays the index of all the records. My plan is to read the page number of each record and save them on database. I have a group field in the report. I don't know how to scan one by one record and get appropriate page number. I tried the following code to get the field value but did not work.
msgbox(rpt.DataDefinition.FormulaFields("name").Text)
It displayed the formula of that field.
I don't know in which order the records fetched using following.
msgbox(rpt.rows(0).item(0))
Please Help me out....
The way your question reads, it sounds like you're trying to generate an "index" for the order records appear in a report and store that index in a database for use in another report. I am not clear at all what you're trying to do with the page number.
In any case, I need to make something clear: the definition of the report (which you're accessing in your code sample) only represents where data will go when the report is formatted - it is not the actual data itself.
At the most basic level, Crystal Reports takes data out of a database and formats it nicely for you on pages. Rather than trying to take data out of a database, put it into a report, then try to read that report to put it back in a database to make another report, why not just do all your data manipulation at the database level itself before going to a report in the first place?
If you really must have that first report, the easiest option you'll have for getting at the formatted data is to export it to excel and access it programmatically through an Excel API - Crystal Reports doesn't have an API for getting at your formatted data (including things like generated page numbers, whatever you're trying to do with them).
You are trying to break few basic rules. For example a report should never change the data. The right way is to handle data processing in a stored procedure or command and to call the report in a separate process. In such way you will be able to control the data change and data visualization separately.
P.S. You probably mean "Identifier" not "Index"

Access Database

I need help in creating an query interface with access database.
In brief, with this query interface I want to see calculated future dates for different steps of a process based on the date the process actually started.
The future dates will always be at a fixed number of days after the start date. I hope I am able to explain this in an understandable manner.
I was thinking of using access forms? Please help me in this. I am not sure of how to proceed with this.
If your data is already in MS Access, then using Access Forms would be your easiest method of displaying that data. If the data is elsewhere, such as in Sql Server, you may be better suited in the long run using a different display technology.
That being said, to select a number of dates, as you would do in Access, you can use the Date Add function. If you had a table Processes with a column StartDate, you could use the query
SELECT *, DateAdd("d",5,StartDate) as "5 Days", DateAdd("d",36,StartDate) as "36 Days"
FROM Processes
to generate a record set to bind your form to. Binding that query to a new form is easy. You just need to change the record source by:
Right click anywhere blank in your new form
Select Properties
Change to the data tab
Click the button next to the text box labeled "Record Source"
Build your query using the built in editor (or, to paste the given SQL, right click in the designer view and select SQL view, then paste)
Close the query building dialog and use your new fields. You can drag them from the field list onto the design surface.