0% found this document useful (0 votes)
11 views

Excel Convert

This document contains code for exporting log data from an Access database to an Excel spreadsheet. The code gets field names and data from a recordset, formats dates and arrays, and copies the data to a new Excel workbook. It uses different methods depending on the Excel version to handle copying the recordset data.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Excel Convert

This document contains code for exporting log data from an Access database to an Excel spreadsheet. The code gets field names and data from a recordset, formats dates and arrays, and copies the data to a new Excel workbook. It uses different methods depending on the Excel version to handle copying the recordset data.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

'------------------------------------------This is for LOG Extract for EXCEL-----------------------------------------|

Private Sub LOG_Click()


Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object'
Dim recArray As Variant
Dim
Dim
Dim
Dim

fldCount As Integer
recCount As Long
iCol As Integer
iRow As Integer

Set xlApp = CreateObject("Excel.Application")


Set xlWb = xlApp.Workbooks.ADD
Set xlWs = xlWb.Worksheets("Sheet1")
xlApp.Visible = True
xlApp.UserControl = True
fldCount = Adodc3.Recordset.Fields.Count
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = Adodc3.Recordset.Fields(iCol - 1).Name
Next
If Val(Mid(xlApp.version, 1, InStr(1, xlApp.version, ".") - 1)) > 8 Then
xlWs.Cells(2, 1).CopyFromRecordset Adodc3.Recordset
Else
recArray = Adodc3.Recordset.GetRows
recCount = UBound(recArray, 2) + 1
For iCol = 0 To fldCount - 1
For iRow = 0 To recCount - 1
If IsDate(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = Format(recArray(iCol, iRow))
ElseIf IsArray(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = "Array Field"
End If
Next iRow
Next iCol
xlWs.Cells(2, 1).Resize(recCount, fldCount).Value = TransposeDim(recArra
y)
End If
xlApp.Selection.CurrentRegion.Columns.AutoFit
xlApp.Selection.CurrentRegion.Rows.AutoFit
End Sub
Function TransposeDim(v As Variant) As Variant
Dim X As Long, Y As Long, Xupper As Long, Yupper As Long
Dim tempArray As Variant
Xupper = UBound(v, 2)

Yupper = UBound(v, 1)
ReDim tempArray(Xupper, Yupper)
For X = 0 To Xupper
For Y = 0 To Yupper
tempArray(X, Y) = v(Y, X)
Next Y
Next X
TransposeDim = tempArray
End Function

You might also like