Get data from ODBC in MS Project - vba

I have a typical project that uses "% work complete". This value actually is entered in an ERP which could be accessed by an ODBC connection. However, I can't figure out how to open this connection. Using VBA I get a compilation error in this line
Dim con As New ADODB.Connection
Is it even possible to gather data from an ODBC source in MS Project?

Related

Connect Microsoft Access to phppgadmin to query in PostgreSQL

My goal is to import data into Microsoft Access to create a database which I can reference from an excel dashboard for analysis.
I can't find any information on how to connect access to allow me to query the database on phpPgAdmin.
Any advice, direction or solution is highly appreciated.
Please let me know if there more details are necessary.
MS Access is a multifaceted thing as many tend to conflate and confuse its frontend GUI .exe application and the distinct backend database (JET/ACE SQL engine which are Windows .dll files). Most of the time we refer to its MS Office app. Technically, MS Access is really the same type of product as phppgadmin: a GUI console to a database, only its default database is the aforementioned engine but can also integrate other ODBC/OLEDB-connected backends including Postgres, Oracle, MySQL, SQL Server, etc.
Through various means, you can integrate MS Access as a medium between PostgreSQL and Excel without any single migration (export/import) of data.
Linked Tables - Directly connect to Postgres tables using its ODBC Driver.
Pass-through queries - Create saved queries using Postgres dialect within MS Access.
ADO Connections (see Importing data programmatically and by using functions) - Bypass MS Access and have Excel connect directly to Postgres also using OLEDB provider or ODBC driver. Below is the programmatic version showing two connection string examples, but you can save connection objects via the Excel ribbon UI.
Dim strConnection
' REFERENCE Microsoft ActiveX Data Objects, #.# Library
Dim conn As ADODB.Connection, rst As ADODB.Recordset
' ODBC AND OLEDB CONNECTIONS (SELECT ONE)
strConnection = "Driver={PostgreSQL};Server=IPaddress;Port=5432;" _
& "Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
strConnection = "Provider=PostgreSQL OLE DB Provider;Data Source=myServerAddress;" _
& "location=myDataBase;User ID=myUsername;password=myPassword;"
conn.Open strConnection
rst.Open "SELECT * FROM myPGTable", conn
By the way, above is the VBA version to be run in an Excel macro but ADO is a COM object and hence can be integrated in COM-interfaced languages including PHP, Python, R, Java, etc.

Connecting to integrated SQL Server in Visual Studio 2016

I'm trying to use OLE DB to connect to the SQL Server that shipped with VS2015 (this should be SQL Server Express I think). Actually I have problems getting my connection string set up. All my attempts resulted in a generic error message.
The errors occurred with this line of code afterwards:
oCon = New OleDbConnection(cConnectstring)
I tried following connection strings:
Server=localhost;Database=main_Table;Trusted_Connection=True;
As well as:
Provider=SQLNCLI11;Data Source=(localdb)\MSSQLLocalDB;DataTypeCompatibility=80;Initial Catalog=main_Table;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
Or:
Provider = sqloledb;Data Source=(localdb)\MSSQLLocalDB; Initial Catalog = main_Table;Integrated Security=SSPI;
where main_Table is the table I try to start with. I used the connection string that I get via right click on that table in the DB explorer as well (that worked for my Access DBs flawlessly).
Does anybody know how to make this work with Ole DB and SQL Server 2016?
Thanks.

Multiple readers access database

I've read about an option in the connection string called MARS (MultipleActiveResultSets), but from what I've gathered it is only a valid argument for Sql Server 2005. Is there an equivalent setting for OleDB to open an access database with multiple readers?
I am aware that I can create multiple connections, one for each reader. I am currently doing this, but it would preferable to execute both readers on a single connection. Here's my current connection string:
"Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\MyDb.mdb;Jet OLEDB:Database Password=MyPassword"

(VBA) Building a ADODB.Connection to Access from Excel

I'm been searching for a while and I can't find any help on this issue.
I have a shared Access 2007 database as a source. I have excel pivots that are linked to a table in that database. I will utimately have multiple excel files linked to the database (and multiple users), and for that reason I'd like to avoid residual open connection to the DB for Access performance reasons, even if the connections are read only.
I've built the connection in excel, but I am attempting to so is write VBA code to open the connection to the access table refresh the pivot cache, then drop the connection. I know that I'm not putting the pieces together correctly. Can someone help me out? Thank you in advance.
Sub ConnectToAccessAttempt()
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DB_Name.accdb;Persist Security Info=False"
ActiveWorkbook.PivotCaches(1).CommandText = "table_Name"
ActiveWorkbook.RefreshAll
End Sub

Is it possible to have a SQL database with Excel files as "data source"?

Is it possible to make some kind of link from SQL to Excel making the Excel documents the true datasource? I don't want any data to be stored in SQL, all data editing will be done in the Excel sheets.
I know this is far from optimal but I don't have a choice, the data needs to stay in Excel.
I know there is an option to do this kind of links in Access and there I can access the data from within VS but I would really prefer SQL.
It's also possible to use the Jet driver directly from your application and skip out SQL server.
I know this isn't a proper answer to your question but another thought that may be useful :)
Yes, you can set up excel as a linked server. You'll need to use a jet driver but this is only available on 32bit machines (Microsoft dropped their support a while back). In other words, this is completely not scale-able and not recommended in most production environments.
If you want to choose Excel as a datasource then you can connect to it using .Net Oledb provider.
Consider VB.Net example below to read rows on excel sheet:
imports System.Data.OleDb
dim connstr as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\exceldb.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
Dim conn As New OleDbConnection(connstr)
conn.Open()
Dim da As New OleDbDataAdapter("select * from [Sheet1$]", conn)
Dim dt As New DataTable()
da.fill(dt)
For i As Integer = 0 To dt.Rows.Count - 1
'do your thing
next
conn.close()
Regards