Consulting

Results 1 to 5 of 5

Thread: Solved: CopyFromRecordset without formatting

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Solved: CopyFromRecordset without formatting

    Hi folks
    I use this line to insert records onto a worksheet from an access database

    [VBA]'Write the records
    ws.Range("A1").Offset(1, 0).CopyFromRecordset rst[/VBA]

    This always removes any formatting on the worksheet. Can I add the records without amending the formatting a sort of:


    .copyfromrecordset.PasteSpecial Paste:=xlPasteValues

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can't recall noticing that, but I don't do it much and when I do it tends to be in a raw data table, non-formatted, so it is not a problem.

    As it seems to destroy existing format and there is no formatting options to the CopyFrom Recordset method, I guess tat you are stuck with formatting the data after the event.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    Thanks for that XLD - not the answer I was hoping for

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sorry, best I could do.

    A thought that may be good for you, dump it to a staging area using CopyFromRecordset, then do a copy-pastevalues to the real area.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You can do as xld suggested or just iterate the recordset. It is not that hard.
    http://vbaexpress.com/kb/getarticle.php?kb_id=889

Posting Permissions

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