Microsoft Access Database

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
trags3
Posts: 394
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Microsoft Access Database

Post by trags3 » Fri Jan 20, 2023 12:54 am

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

cpuandnet
Posts: 25
Joined: Thu Jan 17, 2019 6:43 am

Re: Microsoft Access Database

Post by cpuandnet » Fri Jan 20, 2023 6:18 am

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

trags3
Posts: 394
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Re: Microsoft Access Database

Post by trags3 » Sat Jan 21, 2023 7:55 pm

Hi Tim,
Can you show me an example?

cpuandnet
Posts: 25
Joined: Thu Jan 17, 2019 6:43 am

Re: Microsoft Access Database

Post by cpuandnet » Sun Jan 22, 2023 7:21 am

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.

stam
Posts: 1824
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Microsoft Access Database

Post by stam » Sun Jan 22, 2023 3:38 pm

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.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”