I have used this forum many times to help find answers, unfortunately I have searched high and low to no avail for this issue.
I need at add a field to a table with spaces in the name. I have the [] around the field name but I keep getting the "Error: 3292 Syntax error in field definition". The code works fine using CamelCase, but that would cause more work to correct later.
Red highlighted text is where I encounter the error. Thanks in advance.
I need at add a field to a table with spaces in the name. I have the [] around the field name but I keep getting the "Error: 3292 Syntax error in field definition". The code works fine using CamelCase, but that would cause more work to correct later.
Red highlighted text is where I encounter the error. Thanks in advance.
Code:
Private Sub cmdMatrixUpdate_Click()
strNewField = InputBox("Enter the New Map Name") 'Set the input to variable
strAddField = "ALTER TABLE Web_Matrix_Table ADD COLUMN " & [strNewField] & " YESNO;"
strInsertSQL = "INSERT INTO ReportLookup (Report) VALUES ('" & [strNewField] & "');"
If strNewField = "" Then
Exit Sub
Else
[COLOR=red]DoCmd.RunSQL strAddField[/COLOR] 'Adding the new field to the table
DoCmd.RunSQL strInsertSQL 'Inserting input vairable to ReportLookup Table
End If
Set db = CurrentDb
Set tdf = db.TableDefs("Web_Matrix_Table")
Set field = tdf.Fields(strNewField)
Set property = field.CreateProperty("DisplayControl", dbInteger, 106)
field.Properties.Append property
End Sub