Path database

Good evening group
How do I set the same path in Xojo as the database file to avoid having to write the whole path?

db.DataSource = “Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\Users\User1\Desktop\TEST\XOJO\PROGRAM1\db1.mdb;Uid=;Pwd=;”

is it possible to write something like:
db.DataSource = “Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=AppPath\db1.mdb;Uid=;Pwd=;” ???


first off… don’t put the DB and app in the same place

use Specialfolder.ApplicationData.child(“myDB”).path

You should read up on FolderItem.

It sounds like your db is located in the same folder as the application. If so, then just declaring a new, empty FolderItem will give you the current path to it, like so:

Var f As New FolderItem("")
MessageBox "Current folder = " + f.NativePath

I would recommend you try to create a FolderItem directly for the db, to ensure it exists where you think it is. Something like

Var dbFile As New FolderItem("db1.mdb") //assumes db is in same folder as application
If Not dbFile.Exists Then
  MessageBox "Database not found!"
End If

But as Dave suggests, you shouldn’t put the database in the application folder. It should go in a “user data” folder, either Documents (SpecialFolder.Documents) or the OS specific place for application data (SpecialFolder.ApplicationData as Dave suggests, but you should create a subfolder for your app).

Now, if the database is meant to be a read-only, reference type database, then you could put it in the application’s Resources folder (SpecialFolder.Resouces), and include the file in a Build Step so it is copied into the Resources folder when you run or build.

Meanwhile, thanks for the answers … I tried with f.nativePath and it returns me c: \ Users \ Federico \ Desktop \ Test Xojo \ Program1 \ DebugTest \

but not

C: \ Users \ Federico \ Desktop \ XOJO TEST \ PROGRAM 1 \

which is the Path where the database resides.

Writing f.Name returns me the debug working directory which would be DebugTest.

Can I do a string operation like f.PathName - f.Name? to get the Path of the database?

Can I do a string operation like f.PathName - f.Name? to get the Path of the database?

You should read the manual and understand how the folder item works first.


After spending some hours using Xojo 2021r2.1 (to create a data base project) I now understand why people ask here instead of searching in the Language Reference.

Not only it is more easy (for the eventual lazy people), but the information is so uneasy to reach… and most of the tie it come from the old documentation (from early Xojo - 2013-03 or even older…).

I was "waiting until a large download was running, so I took my two arms, 10 digits, mouse… and time and do a pig work !:exploding_head:

Thank you all for the support. After reading several things, I succeeded in my intent. To avoid having a fixed PATH, I did this by using the SpecialFolder.CurrentWorkingDirectory method

it is STILL a BAD IDEA to put data next to app…

ok, but at least now I know how