Page 1 of 1

Microsoft Access Database

Posted: Fri Jan 20, 2023 12:54 am
by trags3
Correct me if I'm wrong but I don't believe there is a way to directly access the Microsoft Access database with LC.

Tom

Re: Microsoft Access Database

Posted: Fri Jan 20, 2023 6:18 am
by cpuandnet
Hi Tom,

No, not directly. You need to use an ODBC driver via DSN or use a DSNless string. I use it all the time but prefer the DSNless string option because one does not have to setup the DSN on each machine.

Tim

Re: Microsoft Access Database

Posted: Sat Jan 21, 2023 7:55 pm
by trags3
Hi Tim,
Can you show me an example?

Re: Microsoft Access Database

Posted: Sun Jan 22, 2023 7:21 am
by cpuandnet
Yes, of course. This is way oversimplified but you'll get the idea. Assuming your developing on and for Windows...

Code: Select all

local tDatasource
put "Driver={Microsoft Access Driver (*.mdb, *.accdb)};" & \
      "DBQ=c:\your\path\to\your\database.accdb;" into tDatasource
      
local tUsername
put "Admin" into tUsername

local tPassword
put empty into tPassword

local tDatabaseID
put revOpenDatabase("odbc", tDatasource, tUsername, tPassword,) into tDatabaseID
However, keep in mind you don't want to hardcode all your values like this and you'll also want to make sure you include error checking. There are examples and good explanations in the LC dictionary. The majority of the time I use revOpenDatabase, revCloseDatabase, revQueryDatabase, revDataFromQuery, and revDatabaseColumnNamed commands/functions but there are several others that might be useful to you as well.

Re: Microsoft Access Database

Posted: Sun Jan 22, 2023 3:38 pm
by stam
If you want to develop for Mac as well, I think you need to install an ODBC driver for MS Access like this one:
https://actualtech.com/product_access.php, which in theory should allow you to use the same code cross-platform but not sure what licensing costs/requirements you'd have if actually distributing an app.