By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

copy fileds from xls to mdb

P: 6
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).Name
Next

Range("a2").CopyFromRecordset r

r.Close
d.Close

End Sub

Please help..........thank you very much, Buru
Nov 6 '06 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
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).Name
Next

Range("a2").CopyFromRecordset r

r.Close
d.Close

End Sub

Please help..........thank 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 CopyFromRecordset method before.
Nov 6 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.