Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21183

How to Set Column Poperty in Access 2003 Table

$
0
0
Hi All,

When i am Crating a New Data file Through Access 2003 it is show Error "Run Time Error 3265" i will observe all the things but i dont know why it is coming. below please find my vb code and tell me why it is comming? Thanks in Advance...............

Sub CreateAccessTable(sDatabaseToCreate)

Dim catDB As ADOX.Catalog
Dim tblNew As ADOX.Table
Dim cn As ADODB.Connection
Set catDB = New ADOX.Catalog

catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sDatabaseToCreate


Set tblNew = New ADOX.Table
tblNew.Name = "DedctrMaster"

Dim col As ADOX.Column
Dim prp As ADOX.Property
Set col = New ADOX.Column

With col
.ParentCatalog = catDB
.Type = adVarWChar
.Name = "Name"

End With
tblNew.Columns.Append col

' Now add the rest of the columns
With tblNew

With .Columns
'.Append "Name", adVarWChar
.Append "Brdiv", adVarWChar, 50
.Append "Flatno", adVarWChar, 50
.Append "Bldgnm", adVarWChar, 50
.Append "Rdnm", adVarWChar, 50
.Append "Area", adVarWChar, 50
.Append "City", adVarWChar, 50
.Append "State", adVarWChar, 50
.Append "Pin", adVarWChar, 50
.Append "Addch", adVarWChar, 50
.Append "Telecode", adVarWChar, 50

End With
catDB.Tables.Append tblNew
End With

For Each col In tblNew.Columns
For Each prp In col.Properties
If col.Name <> "Brdiv" Then
col.Properties("Required").Value = False

End If
Next
Next

Set cn = catDB.ActiveConnection
SetColumnToNullable cn, "tblNew", "Brdiv", "VARCHAR(50)"


' Add the new Table to the Tables collection of the database.


Set col = Nothing
Set tblNew = Nothing
End Sub

Private Sub SetColumnToNullable(ByRef cn As ADODB.Connection, ByVal TableName As String, ByVal ColName As String, ByVal DataType As String)
cn.Execute "ALTER TABLE " & TableName & " ALTER COLUMN " & ColName & " " & DataType & " NULL"
End Sub

Viewing all articles
Browse latest Browse all 21183

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>