473,485 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to add field properties to MDB with ADOX using VB???

I'm creating a new Access table using ADOX. I can add columns and
indexes, but I'm baffled on how to change field properties. Can
someone give me a hand?

Want to change properties such as: Description (Column property?),
Decimal Places, Caption, Default value, Required indicator, Format,
etc....

TIA,

HexMan

Stripped Code:

Sub CrtTbl1()

Dim Cn As ADODB.Connection, Cat As ADOX.Catalog, objTable As
ADOX. Table, objKey As ADOX.Key
Dim col As ADOX.Column

Cn = New ADODB.Connection
Cat = New ADOX.Catalog
objTable = New ADOX.Table
objKey = New ADOX.Key
col = New ADOX.Column

'Open the connection
Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\WOMSTR.mdb")

'Open the Catalog
Cat.ActiveConnection = Cn

'Create the table
objTable.Name = "WorkOrder"

'Create and Append a new fields to the "Work Order"
objTable.Columns.Append("WODate", DataTypeEnum.adDate)
objTable.Columns.Append("WOInnInd", DataTypeEnum.adInteger)
objTable.Columns.Append("WOTot", DataTypeEnum.adInteger)
objTable.Columns.Append("WORS1", DataTypeEnum.adVarWChar, 20)
'Create and Append a new primary key
objKey.Name = "PrimaryKey"
objKey.Type = KeyTypeEnum.adKeyPrimary
objKey.Columns.Append("WODate")
objKey.Columns.Append("WOTInnInd")
objTable.Keys.Append(objKey)

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
want to change WODate.format = Short Date
change WODate.caption = "Work Order Date"
change WODate.required = True
want to change WOTot.format = General Number
change WOTot.decimalplaces = 2
change WOTot caption = "Total Qty."
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

'Append the newly created table to the Tables Collection
Cat.Tables.Append(objTable)

' clean up objects
objKey = Nothing
objTable = Nothing
Cat = Nothing
Cn.Close()
Cn = Nothing
End Sub
Nov 23 '05 #1
1 11553
Hi Hexman,

You only need ADOX to create the database, the rest you can do with ADONET

Have a look at this sample,

http://www.vb-tips.com/default.aspx?...1-d6dda3c888c8

I hope this helps,

Cor
"Hexman" <He****@Binary.com> schreef in bericht
news:8j********************************@4ax.com...
I'm creating a new Access table using ADOX. I can add columns and
indexes, but I'm baffled on how to change field properties. Can
someone give me a hand?

Want to change properties such as: Description (Column property?),
Decimal Places, Caption, Default value, Required indicator, Format,
etc....

TIA,

HexMan

Stripped Code:

Sub CrtTbl1()

Dim Cn As ADODB.Connection, Cat As ADOX.Catalog, objTable As
ADOX. Table, objKey As ADOX.Key
Dim col As ADOX.Column

Cn = New ADODB.Connection
Cat = New ADOX.Catalog
objTable = New ADOX.Table
objKey = New ADOX.Key
col = New ADOX.Column

'Open the connection
Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\WOMSTR.mdb")

'Open the Catalog
Cat.ActiveConnection = Cn

'Create the table
objTable.Name = "WorkOrder"

'Create and Append a new fields to the "Work Order"
objTable.Columns.Append("WODate", DataTypeEnum.adDate)
objTable.Columns.Append("WOInnInd", DataTypeEnum.adInteger)
objTable.Columns.Append("WOTot", DataTypeEnum.adInteger)
objTable.Columns.Append("WORS1", DataTypeEnum.adVarWChar, 20)
'Create and Append a new primary key
objKey.Name = "PrimaryKey"
objKey.Type = KeyTypeEnum.adKeyPrimary
objKey.Columns.Append("WODate")
objKey.Columns.Append("WOTInnInd")
objTable.Keys.Append(objKey)

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
want to change WODate.format = Short Date
change WODate.caption = "Work Order Date"
change WODate.required = True
want to change WOTot.format = General Number
change WOTot.decimalplaces = 2
change WOTot caption = "Total Qty."
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

'Append the newly created table to the Tables Collection
Cat.Tables.Append(objTable)

' clean up objects
objKey = Nothing
objTable = Nothing
Cat = Nothing
Cn.Close()
Cn = Nothing
End Sub

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2537
by: hytga | last post by:
hi can n e 1 tell me if there's a way to get the column properties from a table? properties like caption, description etc thank you
4
1753
by: Gram | last post by:
Hello, Can anyone help with the following: I wrote an ASP script with allows me to select an MS Access database from a folder, and it shows the tables in this database. If I click a table,...
3
3165
by: Larry | last post by:
In Access each field has individual properties (font, size, color etc). Is there a way around having to enter all these similar properties for each field. This seems so redundant. Is there a...
18
18292
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
7
8497
by: Donald Grove | last post by:
Is it possible to retrieve field properties from a table in access2000 using code? I have tried: " dim dbs as dao.database dim tbl as dao.tabledef dim fld as dao.field dim prop as...
5
16366
by: Sukhanov Volodya | last post by:
Hello, all! Does anybody knows, how I can show an image field SQL Server using VB. NET ? I have an database, which has an table with an field which has type 'image' (the type of field) I want...
5
11712
by: sajithamol | last post by:
I'm trying to read a properties file using BufferedInputStream and getResourceAsStream(),but getting "java.io.IOException: Stream closed' exception. My properties file is not set in the classpath,...
1
7716
by: ahmed222too | last post by:
how can i check if a field is null using VB6 these codes donot work: If rs("lemmaid").Value is null If rs("lemmaid").Value = null If rs("lemmaid").Value =""
1
67091
by: ahmed222too | last post by:
how can i check if an access field is null using VB6 these codes donot work: If rs("lemmaid").Value is null If rs("lemmaid").Value = null If rs("lemmaid").Value =""
0
6960
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7116
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6825
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7275
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4857
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4551
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
595
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
247
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.