Results 1 to 3 of 3

Thread: Replicate a field via DAO

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    Reading, Berkshire, UK
    Posts
    7

    Replicate a field via DAO

    All,

    I need to change the size of a field via DAO. I know how to delete a field and then create a new one, but what I can't seem to work out is how to create a new field, copy the data from the old field and then rename the new field.

    So, I have a field which is 50 characters in size which contains data and I want to make the field 75 characters wide, BUT, retain the existing data.

    Could anyone give me a few pointers ?

    Thanks.

    Chris Swann

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    San Jose, Ca. - USA
    Posts
    302
    try gab2001uk's site, in part of his project he goes over copying a database field by field. It's not exactly what you were asking for but it contains all the info you will need to do what you want to.

    http://homepage.ntlworld.com/graham-bridge/visualbasic/daovsado/index.htm

  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Originally posted by dc8
    All,

    I need to change the size of a field via DAO. I know how to delete a field and then create a new one, but what I can't seem to work out is how to create a new field, copy the data from the old field and then rename the new field.

    So, I have a field which is 50 characters in size which contains data and I want to make the field 75 characters wide, BUT, retain the existing data.

    Could anyone give me a few pointers ?

    Thanks.

    Chris Swann
    You can do that specific job using an Alter Table SQL statement too. If you want to do it through DAO, it's a tad complicated:

    Dim myField As New Field
    Then copy all applicable attributes of the original field into this using:
    MyField.Name = OldField.Name
    MyField.AllowZeroLength = OldField.AllowZeroLength
    etc.

    Then append this MyField to your TableDef object using tabledef.fields.append myfield. Then copy all existing data in the old field into this new field. Once that's done, drop the old field using tabledef.fields.remove. Then once again go through the same process above, only this time changing the Size of the new field object to your new size. Rest of the steps as they are.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width