Hi,
I've been working with a vba code to access dat from DB2 into Excel, but I need no to adapt this code to write data in an Access table.
The procedure to write in Excel is a quite classic one:
Does someone has some code to do the same action in a new Access table ? I've been looking around a bit but could not find something quickly. I've seen someone advising the Addnew method combined with Update but how ?
Thanks
E.
I've been working with a vba code to access dat from DB2 into Excel, but I need no to adapt this code to write data in an Access table.
Code:
Public Function GetData() As ADODB.Recordset
StrQuery = "SELECT * "
StrQuery = StrQuery & "from Table "
StrQuery = StrQuery & " with UR ;"
Set GetData = ReadDB2()'this connects to DB2 and create a recordset with the query
Call DumpRecordset 'this writes in the Excel sheet
ObjCnn.Close
End Function
Code:
r = sr
Do While Not RstMain.EOF 'until end of record set is reached
r = r + 1
c = sc
For Each objField In RstMain.Fields
c = c + 1
If IsNull(objField) Then
Cells(r, c) = "-"
Else
Cells(r, c) = Trim(objField.Value)
End If
Next
RstMain.MoveNext
Loop
Exit Sub
Thanks
E.