473,703 Members | 2,657 Online
Bytes | Software Development & Data Engineering Community
+ 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.Connectio n, Cat As ADOX.Catalog, objTable As
ADOX. Table, objKey As ADOX.Key
Dim col As ADOX.Column

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

'Open the connection
Cn.Open("Provid er=Microsoft.Je t.OLEDB.4.0;Dat a
Source=C:\WOMST R.mdb")

'Open the Catalog
Cat.ActiveConne ction = Cn

'Create the table
objTable.Name = "WorkOrder"

'Create and Append a new fields to the "Work Order"
objTable.Column s.Append("WODat e", DataTypeEnum.ad Date)
objTable.Column s.Append("WOInn Ind", DataTypeEnum.ad Integer)
objTable.Column s.Append("WOTot ", DataTypeEnum.ad Integer)
objTable.Column s.Append("WORS1 ", DataTypeEnum.ad VarWChar, 20)
'Create and Append a new primary key
objKey.Name = "PrimaryKey "
objKey.Type = KeyTypeEnum.adK eyPrimary
objKey.Columns. Append("WODate" )
objKey.Columns. Append("WOTInnI nd")
objTable.Keys.A ppend(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.decimalpl aces = 2
change WOTot caption = "Total Qty."
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

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

' clean up objects
objKey = Nothing
objTable = Nothing
Cat = Nothing
Cn.Close()
Cn = Nothing
End Sub
Nov 23 '05 #1
1 11584
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.c om...
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.Connectio n, Cat As ADOX.Catalog, objTable As
ADOX. Table, objKey As ADOX.Key
Dim col As ADOX.Column

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

'Open the connection
Cn.Open("Provid er=Microsoft.Je t.OLEDB.4.0;Dat a
Source=C:\WOMST R.mdb")

'Open the Catalog
Cat.ActiveConne ction = Cn

'Create the table
objTable.Name = "WorkOrder"

'Create and Append a new fields to the "Work Order"
objTable.Column s.Append("WODat e", DataTypeEnum.ad Date)
objTable.Column s.Append("WOInn Ind", DataTypeEnum.ad Integer)
objTable.Column s.Append("WOTot ", DataTypeEnum.ad Integer)
objTable.Column s.Append("WORS1 ", DataTypeEnum.ad VarWChar, 20)
'Create and Append a new primary key
objKey.Name = "PrimaryKey "
objKey.Type = KeyTypeEnum.adK eyPrimary
objKey.Columns. Append("WODate" )
objKey.Columns. Append("WOTInnI nd")
objTable.Keys.A ppend(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.decimalpl aces = 2
change WOTot caption = "Total Qty."
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

'Append the newly created table to the Tables Collection
Cat.Tables.Appe nd(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
2549
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
1759
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, the fields are displayed. And then I have a button to create a HTML form to suit this table. My problem is, fields that are essential. I would like to mark
3
3179
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 way that I can set up these properties only once and have individual fields use these settings?
18
18399
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 a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
7
8530
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 dao.property
5
16400
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 to save an picture in this field, and then show this picture by an datagrid or other control.... (for each record desirable) Does anybody knows how to do it ? Volodya Sukhanov
5
11746
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, I even tried by incuding the file as a jar in the classpath but invain. My code snippet is: BufferedInputStream bufferedinputstream =new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(s)); where 's' is the name of the...
1
7778
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
67337
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
8750
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8662
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9244
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9111
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8961
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6585
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4421
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2058
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.