Home » excel » sql – Connect Microsoft Access to phppgadmin to query in PostgreSQL

sql – Connect Microsoft Access to phppgadmin to query in PostgreSQL

Posted by: admin May 14, 2020 Leave a comment


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.

How to&Answers:

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.

  1. Linked Tables – Directly connect to Postgres tables using its ODBC Driver.

    Linked Tables icon

  2. Pass-through queries – Create saved queries using Postgres dialect within MS Access.

    Pass-Through Queries

  3. 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
    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.