Question create a table in access, syntax error?

Governor

New member
Joined
Jan 27, 2011
Messages
1
Programming Experience
1-3
i have been trying to create a table in access in the database fileName(variable) but i get the error message
syntax error in field defination.

the code sample is shown below, please help

Public Function CreateTable(ByVal fileName As String) As Boolean
Dim conn As OleDbConnection
Dim objCmd As OleDbCommand
Dim SQL As String

conn = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source=" & Application.StartupPath & "\" & fileName & ".mdb")
SQL = "CREATE TABLE USERS(Path Text(10), Username Text(10), Password Text(10))"
conn.Open()
objCmd = New OleDbCommand(SQL, conn)
objCmd.ExecuteNonQuery()
conn.Close()
MsgBox("table created successfully")
'tblname = FileName
Return True
End Function
 
You should avoid using keywords as identifiers if possible but, if you do want use a keyword as an identifier, you must escape it, e.g. [Password] instead of just Password. Some databases would also accept `Password`, but I'm not sure whether Access is one of them.
 
Back
Top