10

Is there a method to connect to an MS Access database file (.mdb) using QGIS?

In particular I need to connect to a query in it.

The database does not have spatial data.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
toWGS84
  • 499
  • 1
  • 5
  • 14

2 Answers2

11

It's possible to connect via ODBC.

  • In windows, start the ODBC Administrator and define your Datasource (Microsoft Access Driver).
  • In QGIS go to Layer/Add Layer/Vector Layer/database: Type=ODBC.
  • Set up a new Connection. Host should be "localhost" if your database is local on your machine. Database Name is the same name you defined before in the ODBC Administrator.
RolandG
  • 448
  • 2
  • 12
3

... or directly with MS Access Forms ...

There is a simple way:

You are able to define an action for each layer (see: Layerproperties). There you can input a Python script.

from win32com.client import Dispatch

dbname ="dbname.mdb"

dbForm = "frmname"

filter ='id= "[% "ID" %]"'

a=Dispatch("Access.Application")

a.Visible=True

objDB = a.CurrentDb()

if objDB is None:

a.OpenCurrentDatabase(dbname,True)

a.DoCmd.OpenForm(dbForm)

a.forms(dbForm).Filter = filter

a.forms(dbForm).FilterOn = True

Jochen Schwarze
  • 14,605
  • 7
  • 49
  • 117
Gerd
  • 31
  • 1