Public Sub RefreshExcelObject(Optional str As String)
Dim db As DAO.database
Dim rs As DAO.Recordset
Dim sh As OWC11.Worksheet
Dim rng As OWC11.Range
Dim strTable As String
Dim i As Long
Dim j As Long
Dim k As Long
Call Assign_Slide2
Set db = OpenDatabase(Slide2.Tags("DBPath"))
strTable = Slide2.Tags("Table")
Set rs = db.OpenRecordset("Select * from " & strTable)
Set sh = Slide2.Spreadsheet1.Sheets(1)
sh.UsedRange.ClearContents
With sh
Set rng = .Cells(1, 1)
For i = 0 To rs.Fields.Count - 1
rng.Offset(0, i).Value = rs.Fields(i).Name
Next i
i = 1
Do While Not rs.EOF
j = 0
For k = 0 To rs.Fields.Count - 1
rng.Offset(i, j).Value = rs.Fields(k).Value
j = j + 1
Next k
i = i + 1
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End With
db.Close
Set db = Nothing
End Sub
|