copy fileds from xls to mdb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buru
    New Member
    • Oct 2006
    • 6

    copy fileds from xls to mdb

    Hello,

    I create this code which copy some fileds from mdb to an xls and it works fine. But now I have some problems with the opposite operation. Does everyone know a similar function like OpenRecordset but to write into an database?

    Sub example()
    Dim d As Database
    Dim r As Recordset
    Dim SQL$

    SQL$ = "SELECT name,number FROM salvador"

    Set d = OpenDatabase("c :\datos\example .mdb")
    Set r = d.OpenRecordset (SQL$, dbOpenDynaset)

    For i = 0 To r.Fields.Count - 1
    Cells(1, i + 1) = r.Fields(i).Nam e
    Next

    Range("a2").Cop yFromRecordset r

    r.Close
    d.Close

    End Sub

    Please help..........t hank you very much, Buru
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by buru
    Hello,

    I create this code which copy some fileds from mdb to an xls and it works fine. But now I have some problems with the opposite operation. Does everyone know a similar function like OpenRecordset but to write into an database?

    Sub example()
    Dim d As Database
    Dim r As Recordset
    Dim SQL$

    SQL$ = "SELECT name,number FROM salvador"

    Set d = OpenDatabase("c :\datos\example .mdb")
    Set r = d.OpenRecordset (SQL$, dbOpenDynaset)

    For i = 0 To r.Fields.Count - 1
    Cells(1, i + 1) = r.Fields(i).Nam e
    Next

    Range("a2").Cop yFromRecordset r

    r.Close
    d.Close

    End Sub

    Please help..........t hank you very much, Buru
    You still use OpenRecordset, but you might want to check the parameters in the doco.

    You then issue r.AddNew, then fill in the field values (r.Fields(i) = "somevalue"), then issue r.Update.

    I may have missed something important though, because I have never heard of the CopyFromRecords et method before.

    Comment

    Working...