Difference between revisions of "MS Access and MySQL/connecting"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(connecting to ODBC from Access)
m (fixed partial sentence)
Line 1: Line 1:
 
It is possible to use [[Microsoft Access]] as a client – or as an intermediary for [[Visual Basic]] code – while using [[MySQL]] as the database engine. This provides a somewhat less bumpy migration path for VB/VBA applications.
 
It is possible to use [[Microsoft Access]] as a client – or as an intermediary for [[Visual Basic]] code – while using [[MySQL]] as the database engine. This provides a somewhat less bumpy migration path for VB/VBA applications.
  
The basic technique is to set up your [[MySQL]] server as a data source via [[ODBC]]. Then, in MS Access, you link to tables in the ODBC data source by selecting
+
The basic technique is to set up your [[MySQL]] server as a data source via [[ODBC]]. Then, in MS Access, you link to the tables you want in the ODBC data source.
 
===Instructions===
 
===Instructions===
 
* [[adding an ODBC data source in Windows 98]] (the process should be similar for later versions of Windows)
 
* [[adding an ODBC data source in Windows 98]] (the process should be similar for later versions of Windows)

Revision as of 19:30, 31 October 2006

It is possible to use Microsoft Access as a client – or as an intermediary for Visual Basic code – while using MySQL as the database engine. This provides a somewhat less bumpy migration path for VB/VBA applications.

The basic technique is to set up your MySQL server as a data source via ODBC. Then, in MS Access, you link to the tables you want in the ODBC data source.

Instructions

Notes

ODBC appears to translate data types it doesn't understand into Memo fields. This would be fine, except that you can't sort on Memo fields – so you may have to use types which ODBC can handle better. Fields which can't be sorted on also can't be designated as indexes in the data schema (on MySQL's end), or Access will refuse to import the table.

MySQL type MS Access type Notes
TINYTEXT Memo
VARCHAR(255) Text field size = 255

(I'll add to this table as more examples come up.)

Access also has trouble dealing with AUTOINCREMENT fields (usually used for ID) in the table data viewer. If you create a new field but leave the autonumbered ID field blank, on exiting the field Access will show the record as "#deleted". If you close and reopen the table data view, the new data appears. If you enter an ID by hand when you create the record, this problem doesn't happen.

Also, I'm currently having trouble writing to any records via DAO. On "Update", an error message states that another user is trying to write to the same data (which, as far as I can tell, is simply not true; for one thing, I can edit the same record in the MySQL Query Browser on the server side). It may be that this reflects a bug in ODBC. Maybe I should try ADO instead of DAO, but I'm hesitant to start down that path since it involves a lot of code changes and I have generally run into problems (limitations) with ADO under VB6.

The error message:

MS Access error 3197.png