Group:  Microsoft Access ยป microsoft.public.access.developers.toolkitode
Thread: change some fields in an access table

change some fields in an access table
"topaiva" <topaiva[ at ]sapo.pt> 6/2/2007 10:55:56 PM
I'd like to change some fields in an access table from number to text or,
alternatively, create new fields, transfer data to them and delete the prior
fields.
All these in Visual Basic for Access.
Where can I find some examples?
Thanks
Antonio Paiva





Re: change some fields in an access table
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> 6/3/2007 11:14:21 AM
Simplest way probably is to use DDL (Data Definition Language).

To change a field type from numeric to text, you'd use something like:

strDDL = "ALTER TABLE TableName " & _

"ALTER COLUMN FieldName Text(50)"


To create a new field, you'd use something like:

strDDL = "ALTER TABLE TableName " & _

"ADD FieldName TEXT(16)"


To delete a field, you'd use something like:

strDDL = "ALTER TABLE TableName " & _

"DROP COLUMN FieldName"



In all cases, to run the DDL using DAO, you'd use



Dim dbBackend As DAO.Database

Dim strBackend As String

Dim strDDL As String



strBackend = "C:\Folder\File.mdb"



Set dbBackend = OpenDatabase(strBackend)

dbBackend.Execute strDDL, dbFailOnError




To transfer data between two fields, you'd use an Update query:



strSQL = "UPDATE TableName " & _

"SET Field1 = Field2"



You'd run strSQL the same way you ran DDL above.


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)




"topaiva" <topaiva[ at ]sapo.pt> wrote in message
news:4661f5a0$0$2043$a729d347[ at ]news.telepac.pt...
[Quoted Text]
> I'd like to change some fields in an access table from number to text or,
> alternatively, create new fields, transfer data to them and delete the
> prior
> fields.
> All these in Visual Basic for Access.
> Where can I find some examples?
> Thanks
> Antonio Paiva
>
>
>
>
>


Home | Search | Terms | Imprint
Newsgroups Reader