Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData
"Steven Bras" <stevenb...@microsoft.com> wrote in message
news:yrRKyc9...@cppssbbsa01.microsoft.com...
"Robert Mooney" <r...@thomasamerica.com> wrote in message
news:1d6ea01c137d5$274ffdc0$b1e62ecf@tkmsftngxa04...
"Steven Bras" <stevenb...@microsoft.com> wrote in message
news:yrRKyc9...@cppssbbsa01.microsoft.com...
Using Microsoft Visual Basic 6.0 (SP4)
1. Start new standard exe
2. Under References check:
Microsoft ActiveX Data Objects 2.5 Library
Microsoft ADO Ext. 2.1 for DLL and Security
3. Run the following code:
Dim cn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim col As ADOX.Column
Dim tbl As ADOX.Table
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = "bobtest.mdb"
cn.Open
Set cat = New ADOX.Catalog
cat.ActiveConnection = cn
Set tbl = New ADOX.Table
tbl.Name = "new_files"
Set col = New Column
Set col.ParentCatalog = cat
col.Name = "stringField"
col.Type = adVarWChar
col.DefinedSize = 255
col.Properties("Default").Value = "some string value"
tbl.Columns.Append col
cat.Tables.Append tbl
>.
>
Robert Mooney
Manager of Information Systems
The Thomas Group
>.
>
An alternative is to execute an ALTER TABLE statement, which eliminates the
need for ADOX entirely. The syntax is:
ALTER TABLE MyTable ALTER COLUMN MyColumn SET DEFAULT 'DefaultValue'
This should be supported by the Jet 4.0 provider.
Either of these should resolve the problem for you. Good luck!
Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData
This posting is provided AS IS with no warranties, and confers no rights.
You assume all risk for your use. © 2001 Microsoft Corporation. All rights
reserved.
col.Properties("Default").Value = Chr(34) & "some string value" & Chr(34)
Access expects literals to be quoted; in the Access application, this also
causes an error. You must use quotes around your string literals.
Hope this helps!
The error that occurs is:
Run-time error '3421':
Application uses a value of the wrong type for the current
operation.
Checking the VarType(col.Properties("Default").Value)
returns value of 0. This may be a clue to the problem.
Bob Mooney
-----------------------
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim col As ADOX.Column
Dim tbl As ADOX.Table
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString
= "h:\reports\track_dwg_files\bobtest.mdb"
cn.Open
Set cat = New ADOX.Catalog
cat.ActiveConnection = cn
Set tbl = New ADOX.Table
tbl.Name = "new_files"
Set col = New ADOX.Column ''''added "ADOX."
Set col.ParentCatalog = cat
col.Name = "stringField"
col.Type = adVarWChar
col.DefinedSize = 255
Debug.Print VarType(col.Properties
("Default").Value) ''''returns value of 0
col.Properties("Default").Value = Chr(34) & _
"some string value" & Chr(34) '''' added "Chr(34)"
tbl.Columns.Append col
cat.Tables.Append tbl
End Sub
>.
>
I then ran it on my MDAC 2.5 sp2 machine, and the 3421 error occurred. I
applied the Jet service pack 5, and the error persisted. I then updated
MDAC to 2.6 sp1, and the error was eliminated.
You can download this from http://www.microsoft.com/data; I believe the key
is the updated Jet OLEDB Provider.
Good luck!
Bob Mooney
cat.Tables.Append tbl
End Sub
>Steven Bras, MCSD
>Microsoft Developer Support/Visual Basic WebData
>This posting is provided AS IS with no warranties, and
confers no rights.
>You assume all risk for your use. © 2001 Microsoft
Corporation. All rights
>reserved.
>
>.
>
.
ALTER TABLE MyTable ALTER COLUMN MyColumn SET DEFAULT 'DefaultValue'
This will set the default value for the column.
Hope this helps.
Ramesh Thyagarajan
Microsoft Support.