Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 24th, 2003, 08:45 PM
jalbores jalbores is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 7 jalbores User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question adding columns

I want to add or delete columns or fields from a table in execution time, i
mean, without editting the table design manually, i think it is maybe
possible by code, i would like some help on how to do this. I also
want to edit some column properties in excution time, like change its
name or its format.

thanks

Reply With Quote
  #2  
Old November 24th, 2003, 10:35 PM
Stev Stev is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Queensland, Australia
Posts: 256 Stev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 53 sec
Reputation Power: 5
This is possible using VB code. You need to use append and delete methods on the TableDef and Fields collection objects.

Reply With Quote
  #3  
Old November 25th, 2003, 10:14 AM
jalbores jalbores is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 7 jalbores User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks Stev, i´m going to take a look at that, it would be really helpful if you could post an example about this.

thanks again

Reply With Quote
  #4  
Old November 26th, 2003, 02:10 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Here is a short sample:

Dim DBa As Database 'variable declaration
Dim TDa As TableDef

Set DBa = CurrentDb 'open the database

Set TDa = DBa.TableDefs!tblEszkoz1FKarton_Ado01 ' open the TableDef object pointing to the table you wish to modify

TDa.Fields.Append TDa.CreateField("FieldName", dbDouble) 'append a field

TDa.Fields.Delete "FieldName" 'delete a field

See Append or CreateField Help topics for detailed help.

BRegs,

TBÁrpi

Reply With Quote
  #5  
Old November 26th, 2003, 02:14 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Here is a short sample:

Dim DBa As Database 'variable declaration
Dim TDa As TableDef

Set DBa = CurrentDb 'open the database

'********** I modified the following line because it can be misunderstood because of the table name I used in my earlier message.**********

Set TDa = DBa.TableDefs!TableName ' open the TableDef object pointing to the table you wish to modify

TDa.Fields.Append TDa.CreateField("FieldName", dbDouble) 'append a field

TDa.Fields.Delete "FieldName" 'delete a field

See Append or CreateField Help topics for detailed help.

BRegs,

TBÁrpi

Reply With Quote
  #6  
Old November 27th, 2003, 09:23 AM
jalbores jalbores is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 7 jalbores User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i thank you for helping me, i understand the logic in your example, however, in your variable declaration yo have Database and TableDef as variable types. The question is how to define those types because i´m assuming that they are not already included. Please point me if i'm wrong.

thanks.

bye

Reply With Quote
  #7  
Old November 27th, 2003, 09:53 AM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Use this declaration instead:

Dim DBa As DAO.Database
Dim TDa As DAO.TableDef

Compile the module. If you receive error message sayimg 'Variable not defined', then you need to check if Microsoft DAO 3.51 Object Library (file: DAO351.OLB) (or 3.6, file is DAO36.OLB) is properly registered. To do this, go to Tools->References... menu path in VBA editor.

BRegs,

TBÁrpi

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > adding columns


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway