Private Sub GenerateFile()
On Error GoTo err_trap
'Generate x File if x Checkbox is marked
If Me.CBa.Value = True Then
cmd.CommandText = "EXEC dbo.ipg_PayrollFilea '" & Trim(Me.TbBeginDate.Value) & "', '" & Trim(Me.TbEndDate.Value) & "'"
'cmd.CommandText = "SELECT * FROM SOP10100"
End If
'Generate y File if y Checkbox is marked
If Me.CBb.Value = True Then
cmd.CommandText = "EXEC dbo.ipg_PayrollFileb '" & Trim(Me.TbBeginDate.Value) & "', '" & Trim(Me.TbEndDate.Value) & "'"
'cmd.CommandText = "SELECT * FROM POP10100"
End If
Set rst = cmd.Execute
Dim oApp As New excel.Application
Dim oBook As Office
Dim oSheet As New excel.Worksheet
Set oBook = oApp.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
'Add the field names in row 1
Dim i As Integer
Dim iNumCols As Integer
iNumCols = rst.Fields.Count
For i = 1 To iNumCols
oSheet.Cells(1, i).Value = rst.Fields(i - 1).Name
Next
'Add the data starting at cell A2
oSheet.Range("A2").CopyFromRecordset rst
'Format the header row as bold and autofit the columns
With oSheet.Range("a1").Resize(1, iNumCols)
.Font.Bold = True
.EntireColumn.AutoFit
End With
'Open the Excel Workbook for the user
oApp.Visible = True
oApp.UserControl = True
'Close the Database and Recordset
rst.Close
Exit Sub
err_trap:
MsgBox Err.Number & " " & Err.Description
CancelLogic = True
KeepFocus = True
Exit Sub
End Sub