Syntax Error 3320 (1 Viewer)

NauticalGent

Ignore List Poster Boy
Local time
Today, 00:39
Joined
Apr 27, 2015
Messages
6,321
Greetings AWF,

I cant believe I cant figure this out, yet here I am. I am trying to do something cute that involves Creating a table with default values. One of those values contains a comma and it has got me stumped...

Code:
Public Sub CreateNewTable()
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim Fld01 As DAO.Field
    Dim Fld02 As DAO.Field
    Dim Fld03 As DAO.Field
    
    Set db = CurrentDb
    Set tdf = db.CreateTableDef("tblSQLTables")
    Set Fld01 = tdf.CreateField()
    Set Fld02 = tdf.CreateField()
    Set Fld03 = tdf.CreateField()
    
    With Fld01
      .Name = "SQLTableName"
      .Type = dbText
      .Size = 50
      .Required = True
    End With
    
    With Fld02
      .Name = "SQLServer"
      .Type = dbText
      .Size = 50
      .DefaultValue = "[COLOR="Red"]SEUSQL50\INST01,1437[/COLOR]"
    End With
    
    With Fld03
      .Name = "SQLdb"
      .Type = dbText
      .Size = 50
      .DefaultValue = "RMC_Tracker"
    End With
    
    
    tdf.Fields.Append Fld01
    tdf.Fields.Append Fld02
    tdf.Fields.Append Fld03
    
    db.TableDefs.Append tdf
    db.TableDefs.Refresh
    
    Application.RefreshDatabaseWindow

End Sub

When I run it, I get the following error:
3320 - Syntax error (comma) in table-level validation expression.

I have tried:
Code:
= "'SEUSQL50\INST01,1437'" ' This throws no error, but includes the single quotes
= "SEUSQL50\INST01" & "," & "1437"
= "SEUSQL50\INST01," & "1437"
= "SEUSQL50\INST01" & ",1437"
= "SEUSQL50\INST01" & Chr(44) & "1437"

And with the exception of the first example, they all throw the same error...

I KNOW it has to be something easy, but I cannot figure it out, someone throw me a bone...:cool:
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 05:39
Joined
Feb 19, 2013
Messages
16,607
try

.DefaultValue = """SEUSQL50\INST01,1437"""

works for me.

Not sure why the comma makes a difference, but it does

edit: as with your single quotes the double quotes do appear as the default value. But if you go into the table design and remove the quotes, you will get a more detailed error description - basically you can't have default values with commas unless surrounded with quotes. The quotes don't appear when the table is viewed
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:39
Joined
Oct 29, 2018
Messages
21,454
Hi John. Try:
Code:
.DefaultValue = "[COLOR=Red]""[COLOR=Black]SEUSQL50\INST01,1437[/COLOR]""[/COLOR]"


Edit: Oops, too slow...
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 00:39
Joined
Apr 27, 2015
Messages
6,321
Thanks, both of you. Worked like a charm, so easy yet just out of reach!
 

Users who are viewing this thread

Top Bottom