PDA

Click to See Complete Forum and Search --> : ADO Help


Gary.Lowe
Nov 3rd, 2000, 08:13 AM
Dear All

I am having a few problems creating tables using ADO

I get the following error -2147217900 : Syntax error in field definition.

here is the code to create the database

'\\Create Database
adoCat.Create ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\LogFileCheck.mdb;")

The database creation works fine

It is when I try to create a table as follows


Public Function bfn_ADOCreateTable(ByVal sSQL As String) As Boolean
On Error GoTo ErrErrADOCreateTable

cn.Open adoCat.ActiveConnection '\\Set the connection
cn.Execute sSQL
bfn_ADOCreateTable = True '\\Table creation successful

Exit_ErrADOCreateTable: '\\Exit routine
Exit Function

ErrErrADOCreateTable: '\\Error Routine
Select Case Err
Case Err
For Each objErr In cn.Errors '\\Check errors in ADO
If strError = "" Then
strError = objErr.Number
strError = strError & " : " & objErr.Description
Else
strError = strError & vbCrLf
strError = objErr.Number
strError = strError & " : " & objErr.Description
End If
Next

If strError = "" Then '\\Check general errors
strError = Err.Number & " : " & Err.Description
End If

Err.Clear
cn.Errors.Clear
bfn_ADOCreateTable = False '\\Table creation failed
Resume Exit_ErrADOCreateTable
End Select
End Function

This is the point the error occurs. The error occurs on the

cn.Execute sSQL

part of the code in the table creation function.

The SQL is as follows

CREATE TABLE tblHeader (ID AUTOINCREMENT CONSTRAINT HeaderID PRIMARY KEY, type INTEGER,flags INTEGER,modifiers INTEGER,till INTEGER,seqno INTEGER,when INTEGER,oper INTEGER,trans INTEGER);


I have tried to run this SQL by copying the SQL directly into an access query and running it. The table is created with no problems.

As soon as I run it in VB I get the error.

Can you help?

Thanks

monte96
Nov 3rd, 2000, 08:38 AM
Post the SQL. That's where the error is.

Gary.Lowe
Nov 3rd, 2000, 08:41 AM
Thanks monte96 but I've Sussed it

I have now precceded all the field names with fld_(field name)
and it worked.

One of the fields must have been a reserved word in ADO.