Forum > Databases

[SOLVED]*.mdb ->Sort of chicken before the egg

(1/3) > >>

What I can do:
I finally got my utills to load a *.mdb file and do some basic operation and learning more everyday, so here is my road block for today.
I have a routine that checks if the *.mdb exist, if so load it but if not create it.
But our good friend Microsoft make Access file have to be full path and short name.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- TheDBFile:='GavinWords.mdb'; TheDBFile:=ExtractFilePath(Application.ExeName)+TheDBFile; TheDBFile:=ExtractShortPathName(TheDBFile); TheDBFile comes out nil because " TheDBFile:=ExtractShortPathName(TheDBFile);" the file must exist first.
any ideals to point me in a direction

wp:
The first two lines are enough to define the full path to the mdb file, provided that it resides in the applications binary directory. Why do you need the third line? Must confess that I never used ExtractShortPathName...

After deciding whether file already exists you eventually must create a new one. Please note that the SQL "CREATE TABLE" works only when a mdb file exists. Take a look at https://wiki.freepascal.org/MS_Access#Create_a_database_programmatically to see how an empty mdb (or accdb) file can be created by code.

What I can do:
Thank you wp, just so happen that is the exact code i use.
The problem is the ODBC Microsoft driver, the wiki ACESS examples all examples fail me except for defining the UserDSN file as " (Microfsoft Access Driver (*.mbd,*accdb)" 
then I add this "AConn.Params.Add('DBQ='+FN);"  but the kicker is the name has to be short name format.

What I can do:
These were my test runs
[FAIL]      f:='CarCare.mdb;
[FAIL]      f:=ExtractFilePath(Application.ExeName)+'CarCare.mdb';
[Success] f:=ExtractShortPathName(ExtractFilePath(Application.ExeName)+'CarCare.mdb');
'CarCare.mdb' is an existing file

paweld:
you must precede the file with a directory path, but it does not have to be a direct path, it can be indirect, that is.
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---conn.Params.Add('DBQ=.\accessdbfile.mdb');  

Navigation

[0] Message Index

[#] Next page

Go to full version