Paulsburbon
Registered User.
- Local time
- Today, 09:21
- Joined
- May 3, 2005
- Messages
- 65
I'm trying hard to learn VB but having a hard time with uncommented code I have found on the net. Here is the Problem:
I need to take a report[invoice] and make it into an excel file to send to customers that prefer that format. I sure I can format the excel file in the way I want it but getting the actual data[items ordered] to the sheet is a bit hard for me. Here is the code I'm using:
Private Sub Toggle110_Click()
Dim rs As Recordset
Dim intMaxCol As Integer
Dim intMaxRow As Integer
Dim qdf As QueryDef
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set qdf = CurrentDb.QueryDefs("qryInvoice")
qdf.Parameters(0) = Forms!frmClaims!idsClaimNumber
Set rs = qdf.OpenRecordset
intMaxCol = rs.Fields.Count
If rs.RecordCount > 0 Then
rs.MoveLast: rs.MoveFirst
intMaxRow = rs.RecordCount
Set xlApp = New Excel.Application
With xlApp
.Visible = True
Set xlBook = .Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
With xlSheet
.Range(Cells(1, 1), .Cells(intMaxRow, intMaxCol)).CopyFromRecordset rs
End With
End With
End If
End Sub
So far I understand most of this but the .Range is coming back with a fail error. Any help would be really nice.
I need to take a report[invoice] and make it into an excel file to send to customers that prefer that format. I sure I can format the excel file in the way I want it but getting the actual data[items ordered] to the sheet is a bit hard for me. Here is the code I'm using:
Private Sub Toggle110_Click()
Dim rs As Recordset
Dim intMaxCol As Integer
Dim intMaxRow As Integer
Dim qdf As QueryDef
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set qdf = CurrentDb.QueryDefs("qryInvoice")
qdf.Parameters(0) = Forms!frmClaims!idsClaimNumber
Set rs = qdf.OpenRecordset
intMaxCol = rs.Fields.Count
If rs.RecordCount > 0 Then
rs.MoveLast: rs.MoveFirst
intMaxRow = rs.RecordCount
Set xlApp = New Excel.Application
With xlApp
.Visible = True
Set xlBook = .Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
With xlSheet
.Range(Cells(1, 1), .Cells(intMaxRow, intMaxCol)).CopyFromRecordset rs
End With
End With
End If
End Sub
So far I understand most of this but the .Range is coming back with a fail error. Any help would be really nice.