Create MS-Access Table via Delphi

Hello all,

First of all, I didn't write this question except after hammering the entire section and the Internet in general for days looking for the right answer, but unfortunately, some answers are too old some are not complete etc.

I saw the chapters in Delphi section but it requires ADOX 2.x dll which is not in my system. I have msadox.dll (ver 6) and I tried to import it but Delphi XE2 seems not to recognize the file. So I decided to go with the old-fashioned way.

Anyway, the program that will create a table after clicking a button. Everything is set up perfectly except the query sentence that will be sent to the database.

Here is the code:

procedure TAddIndivdualForm.OkClick(Sender: TObject);
Name: string;
QString: string;
Name := NameEdit.Text;

QString:= 'CREATE TABLE  ' + Name + ' (ProcessCaleneder DateTime, IndivName text(30), 
Position text(30), Mobile text(20), Salary Currency, Notes text(255))';

with MainForm.IndivdualsQuery do
  ConnectionString := 
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Mark\Desktop\Database.mdb;';

Open in new window

The result after clicking the button is: Syntax error in field definition. (because of the query)

the SQL.Add parameters were those of QString variable. But I took the string out, chopped it up a little and added string variables in between. String concatenation could be a huge mess sometimes in my personal opinion.

I tried to find the MS-Access queries reference on the net but I couldn't. I want to know how the sql queries were formed ?

So, to keep the post organized, here are my questions:

1. If you can correct the query sentence, I appreciate that.
2. Where do I find the queries reference ?
3. How do I make the XE2 IDE recognize ADOX 6.0 ?
4. The jet engine used in my example is ver 4.0 and .mdb, how do I make the IDE recognize access 2010 files ? will this enforce the other users of my app to install the distribution package ?
I appreciate your help even if you answer a portion of the questions.

Who is Participating?

Improve company productivity with a Business Account.Sign Up

gxsConnect With a Mentor Author Commented:
Well, Today was a weird one to me,

Above all of the problems above, the final problem was replacing the fields names in the SQL query string  with Arabic ones.

I modified the string accidentally into:

QString:= 'CREATE TABLE ' + Name + ' ([¿¿¿¿¿¿¿] DateTime, [¿¿¿¿¿] text(30), [¿¿¿¿¿¿ ¿¿¿¿¿¿¿] text(30), [¿¿¿¿¿¿] text(20), [¿¿¿¿¿¿] Currency, [¿¿¿¿¿¿¿] text(255))';

It worked like charm! without the square brackets, it would give me a ms-access syntax error due to the string being manipulated by the Arabic words.

I'm just amazed by how such a very tiny modification solved the problem X__X
1 - What is the error when you execute the sql string, first point of attack
2 - ?
3 - ADOX from memory (its been a while! was long winded - I would stick with SQL!)
4 - Make the connection string based on a setting for the IDE either from an ini file, xml file or registry setting when you install the application
gxsAuthor Commented:
Thanks MMTadmin for you reply,

1. It is in the SQL sentence, because when I delete some parts, It works fine.
2. I mean the access sql queries reference ( Every sql language has its own sql queries methods )
3. I considered many solutions such as SQL, Absolute Database but the program is so simple and the database is local.
4. The connection string wouldn't be valid if the IDE doesn't recognize the appropriate database driver.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

gxsAuthor Commented:
Regarding the recognition of *.accdb files.

I have seen this video a couple of days ago. It is about this specific subject.

My IDE doesn't show the same driver when the guy in the video navigates to Microsoft Access Driver (*.accdb).

I have installed Microsoft Access Database Engine 2010 Redistributable, but still, no luck :p

and by the way, the language in the video is Portuguese and I don't speak it.
gxsAuthor Commented:
AAAh, finally, I have stabbed the query problem in the heart X__X

The word ([Position] text(30)) appears to be somehow a reserved word ? Because of that I was asking about the queries reference.

Hope you answer the rest of the questions
gxsAuthor Commented:
^^^ experts-exchange doesn't support UNICODE? ooooh you kidding me :"(
Geert GOracle dbaCommented:
in google type "ms access sql reference"
or any other "database type sql reference"

i have to admit, it's not user friendly navigating the websites to find the accurate statement on msdn for access
an index somewhere would be way more helpful

this list the syntax on the statements

reserverd word list

looks like position is not in this list

the square brackets are usually a must in access
gxsAuthor Commented:
No one is willing to help :"(


For days and years to come and for those who are looking for creating tables:

Here is a simpler way using TADOCommander:

procedure TAddStaffForm.OkClick(Sender: TObject);
Name: string;
QString: string;

Name := NameEdit.Text;
QString:= 'CREATE TABLE ' + '[' + Name + ']' + ' ([¿¿¿¿¿¿¿] DateTime, [¿¿¿¿¿¿ ¿¿¿¿¿¿¿] text(30), [¿¿¿¿¿¿] text(20), [¿¿¿¿¿¿] Currency, [¿¿¿¿¿¿¿] text(255))';

// StaffCommander is a TADOCommander component
MainForm.StaffCommander.CommandText := QString;

// StaffPuller is a TADOTable component
MainForm.StaffPuller.Active := False;
MainForm.StaffPuller.TableName := name;
MainForm.StaffPuller.Active := True;

Open in new window

The square brackets are added to avoid foreign language mistakes in the SQL string. They are not needed if the language is English, French etc. But recommended.
I've been using KaDao Components for Delphi and MS Access for years without any problems.

Perhaps this may also be an option for you...
You probably need to cast all your field and table names into ASCII.  The database engine you are using is probably old enough that it is not unicode capable.
gxsAuthor Commented:
The best solution
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.