Would require VBA code manipulating TableDef collection to modify properties of table fields (assuming Format property can be addressed with code). Agree with Paul, run DELETE/UPDATE/INSERT sql actions instead of repeatedly deleting/creating table.
I do have procedure that creates table and modifies AllowZeroLength property of text type fields. Haven't used it in a long time. Excerpt:
Code:
Set cn = New ADODB.Connection
'connect to the backend database
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & gstrBasePath & "Data\LabData.accdb'"
'create the test table
cn.Execute "CREATE TABLE " & Me.tbxTestNum & " (LabNum text(12) PRIMARY KEY Not Null, method text(30) Not Null);"
'set table link
Set tdf = CurrentDb.CreateTableDef(Me.tbxTestNum)
tdf.SourceTableName = Me.tbxTestNum
tdf.Connect = "; DATABASE=" & gstrBasePath & "Data\LabData.accdb"
CurrentDb.TableDefs.Append tdf
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM BuildTable;", CurrentProject.Connection, adOpenStatic, adLockPessimistic
'must use DAO to set AllowZeroLength property, I don't allow zero length fields and Access defaults to Yes
Set db = DBEngine.OpenDatabase(gstrBasePath & "Data\LabData.accdb")
While Not rs.EOF
If rs!DataField <> "LabNum" And rs!DataField <> "method" Then
'create field in new table
cn.Execute "ALTER TABLE " & Me.tbxTestNum & " ADD COLUMN " & _
rs!DataField & " " & IIf(rs!DataType = "Boolean", "Bit", rs!DataType) & _
IIf(rs!DataType = "Text", "(" & rs!FieldSize & ")", "") & ";"
End If
If rs!DataType = "Text" Then
'change the AllowZeroLength default Yes to No
db.TableDefs(Me.tbxTestNum).Fields(rs!DataField).AllowZeroLength = False
End If
rs.MoveNext
Wend