i have the following function that will export a query to a spreadsheet. The issue is that when the value of the field has any leading zero's they get dropped. I don't do much with Excel so I'm not sure where to look first to resolve this. Any help is appreciated.
Code:
Option Compare Database
Function ExcelExport()
Dim strFile As String
Dim rsRegn As Recordset
Dim intRow As Integer
Dim strDate As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
DoCmd.SetWarnings False
strFile = "c:\Template.xls"
strDate = Format(Date, "mmddyy")
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Workbooks.Open strFile
With xlApp
.Sheets("GL Wire Adjustments").Cells.Select
.Selection.Delete
.ActiveSheet.Range("A1").Value = "Branch Number"
.ActiveSheet.Range("B1").Value = "Client Number"
.ActiveSheet.Range("C1").Value = "Fee"
.ActiveSheet.Range("D1").Value = "Description"
.Range("A1", "D1").Select
With xlApp.Selection.Interior
.ColorIndex = 48
End With
With xlApp.Selection.Font
.Size = 10
.Bold = True
End With
Set rsRegn = CurrentDb.OpenRecordset("qryGl")
intRow = 2
rsRegn.MoveFirst
While Not rsRegn.EOF
.ActiveSheet.Range("A" & intRow).Value = rsRegn.Fields(0).Value
.ActiveSheet.Range("B" & intRow).Value = rsRegn.Fields(1).Value
.ActiveSheet.Range("C" & intRow).Value = rsRegn.Fields(2).Value
.ActiveSheet.Range("D" & intRow).Value = rsRegn.Fields(3).Value
intRow = intRow + 1
rsRegn.MoveNext
Wend
TheEnd:
.Columns("A:D").Select
With xlApp.Selection
.HorizontalAlignment = xlLeft
End With
.ActiveSheet.Cells.EntireColumn.AutoFit
.Range("A2").Select
.ActiveWorkbook.SaveAs "c:\" & strDate & "Output.xls", , , "password"
.Quit
End With
DoCmd.SetWarnings True
End Function