abduhsuryadi
New Member
- Joined
- Dec 23, 2012
- Messages
- 2
I have a table, name myTable in access database in desktop\jwb.accdb. the table has more then 50 fields. the name of the fields: answer1, answer2,....answer50.
And I have data in excel column A1 to A50 that I want to add to these fields.
data in A1 to answer1
data in A2 to answer2
data in A3 to answer3
how can i make my code simple?
my current code is mostly like this:
thanks for the help
And I have data in excel column A1 to A50 that I want to add to these fields.
data in A1 to answer1
data in A2 to answer2
data in A3 to answer3
how can i make my code simple?
my current code is mostly like this:
Code:
Dim sSQL As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Environ("UserProfile") & "\Desktop\jwb.accdb;Persist Security Info=False"
Set rs = New ADODB.Recordset
sSQL = "myTable"
rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!Answer1 = Range("A1")
rs!Answer2 = Range("A2")
rs!Answer3 = Range("A3")
'and soon....
rs.Update
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
thanks for the help