dbTalk Databases Forums  

How to add property to table (with VB-code)?

comp.database.ms-access comp.database.ms-access


Discuss How to add property to table (with VB-code)? in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jansb000
 
Posts: n/a

Default How to add property to table (with VB-code)? - 10-03-2003 , 06:14 AM






ACCESS 97

When I want to add a property to a newly created table I get the error:
"Object or With variable not set"

Any suggestions on what is wrong with the line where I want to add the
property?
This is the code:

Dim db As Database
Dim td As TableDef

Set db = CurrentDb
Set td = db.CreateTableDef(TechName)

With td
.Fields.Append .CreateField("ID", dbLong)
.Fields.Append .CreateField("Name", dbText, 50)
.Fields.Append .CreateField("Value", dbText, 100)
.Fields.Append .CreateField("Type", dbText, 20)

'Add properties (doesn't work)
-> .Properties.Append .CreateProperty("Version", dbText, "1.00a")

'Append the new TableDef object to the database.
db.TableDefs.Append td
End With



Reply With Quote
  #2  
Old   
jansb000
 
Posts: n/a

Default Re: How to add property to table (with VB-code)? - 10-03-2003 , 06:25 AM






This modified version has the same problem

Quote:
Dim db As Database
Dim td As TableDef
Dim pr As Property

Set db = CurrentDb
Set td = db.CreateTableDef(TechName)

With td
.Fields.Append .CreateField("ID", dbLong)
.Fields.Append .CreateField("Name", dbText, 50)
.Fields.Append .CreateField("Value", dbText, 100)
.Fields.Append .CreateField("Type", dbText, 20)

'Add properties (doesn't work)
-> .Properties.Append .CreateProperty("Version", dbText, "1.00a")
pr = .CreateProperty("x", , "123") ' <== Error occurs here
.Properties.Append pr
Quote:
'Append the new TableDef object to the database.
db.TableDefs.Append td
End With





Reply With Quote
  #3  
Old   
Ray
 
Posts: n/a

Default Re: How to add property to table (with VB-code)? - 10-06-2003 , 10:59 AM



"jansb000" <jansb000 (AT) planet (DOT) nl> wrote

Quote:
ACCESS 97

When I want to add a property to a newly created table I get the error:
"Object or With variable not set"

Any suggestions on what is wrong with the line where I want to add the
property?
This is the code:

Dim db As Database
Dim td As TableDef

Set db = CurrentDb
Set td = db.CreateTableDef(TechName)

With td
.Fields.Append .CreateField("ID", dbLong)
.Fields.Append .CreateField("Name", dbText, 50)
.Fields.Append .CreateField("Value", dbText, 100)
.Fields.Append .CreateField("Type", dbText, 20)

'Add properties (doesn't work)
-> .Properties.Append .CreateProperty("Version", dbText, "1.00a")

'Append the new TableDef object to the database.
db.TableDefs.Append td
End With
Hello Jansb000,

Check out the following code which I use in an automated
system to check and see if the table exists. If not, it
makes it.

Dim fld1 As Field, fld2 As Field, fld3 As Field
Dim fld4 As Field, fld5 As Field
Dim idx As Index, fldIndex As Field

' Create new table with four fields if needed.
Set tdf = db.CreateTableDef("tblDataSearchedFor")
Set fld1 = tdf.CreateField("RecordID", dbLong)

fld1.Attributes = fld1.Attributes + dbAutoIncrField

Set fld2 = tdf.CreateField("MDBFound", dbText, 50)
Set fld3 = tdf.CreateField("TableFound", dbText, 50)
Set fld4 = tdf.CreateField("FieldFound", dbText, 50)
Set fld5 = tdf.CreateField("StringSearchedFor", dbText, 50)

' Append fields.
tdf.Fields.Append fld1
tdf.Fields.Append fld2
tdf.Fields.Append fld3
tdf.Fields.Append fld4
tdf.Fields.Append fld5

' Create primary key index.
Set idx = tdf.CreateIndex("PrimaryKey")
Set fldIndex = idx.CreateField("RecordID", dbLong)

' Append index fields.
idx.Fields.Append fldIndex

' Set Primary property.
idx.Primary = True

' Append index.
tdf.Indexes.Append idx

' Append TableDef object.
db.TableDefs.Append tdf
db.TableDefs.Refresh

Set tdf = Nothing

As an example, you can put the code into the ON CLICK
property of a button on a form. Perhaps you can see what
this is doing to fix your code.

Regards,

Ray


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.