Maybe I should explain better what I am trying to do and what is
happening.
1) I have a mainform where the user can select from on or a combination
of
4 comboboxes then enter a Start date and End date, then click the select
button on the mainform. Using the code below, the subform then displays
the
selected information:
Private Sub Select_Click()
Dim strSQL As String
strSQL = "SELECT [tblHours_Worked].ProjectID, " _
& "[tblHours_Worked].DisciplineName, " _
& "[tblHours_Worked].SectionNumber, " _
& "[tblHours_Worked].LastName, " _
& "[tblHours_Worked].[FirstName], " _
& "[tblHours_Worked].[SLC Code], " _
& "[tblHours_Worked].[Week Ending], " _
& "[tblHours_Worked].[PHW], " _
& "[tblHours_Worked].[AHW] " _
& "FROM [tblHours_Worked] WHERE True"
If Not IsNull(Me![DisciplineName]) Then
strSQL = strSQL & " AND [DisciplineName] = '" & Me![DisciplineName] & "'"
End If
If Not IsNull(Me![SectionNumber]) Then
strSQL = strSQL & " AND [SectionNumber] = " & Me![SectionNumber] & ""
End If
If Not IsNull(Me![ProjectID]) Then
strSQL = strSQL & " AND [ProjectId] = '" & Me![ProjectID] & "'"
End If
If Not IsNull(Me![LastName]) Then
strSQL = strSQL & " AND [LastName] = '" & Me![LastName] & "'"
End If
If Not IsNull(Me![Start_Date]) Then
strSQL = strSQL & " AND [Week Ending] >= " & Format(Me![Start_Date],
"\#mm\/dd\/yyyy\#")
End If
If Not IsNull(Me![EndDate]) Then
strSQL = strSQL & " AND [Week Ending] <= " & Format(Me![EndDate],
"\#mm\/dd\/yyyy\#")
End If
Debug.Print strSQL
Me.frmHours_Worked_subform.Form.RecordSource = strSQL
End Sub
2) I have position a Export to Excel button on the mainform. I am trying
to have the information displayed in the subform exported to excel.
The recordsource for the subform is coded as follows:
SELECT tblHours_Worked.ProjectID, tblHours_Worked.DisciplineName,
tblHours_Worked.SectionNumber, tblHours_Worked.LastName,
tblHours_Worked.FirstName, tblHours_Worked.[SLC Code],
tblHours_Worked.[Week
Ending], tblHours_Worked.PHW, tblHours_Worked.AHW FROM tblHours_Worked
WHERE
True;
Now this is currently the code being used to export the information in the
subform to excel. The user can double click on the fields in the subform,
enter start and end dates:
Private Sub SectionNumber_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = Me.SectionNumber
stDocName = "pivtblHours_Worked"
DoCmd.OpenForm stDocName, acFormDS, , _
"SectionNumber = " & stLinkCriteria
DoCmd.OutputTo acOutputForm, "pivtblHours_Worked", "(*.xls)", _
"\\Escfil02\4400_Shared\4400_Project_Control\Resource Management
DB\pivtblHours_Worked_template_Section.xls", True, ""
Debug.Print stLinkCriteria
End Sub
I don't want the user to have to double click then enter a start and end
date, I would like for them to be able to click the Export to Excel button
and the information displayed exports to excel. Using the query:
qryHours_Worked_Export. No go to a pivot table form then to Excel.
Hopefully this help better understand what I a asking. If not I'll try to
better to explain.
Thanks
--
tmdrake
Jeanette Cunningham said:
tmdrake,
build a query based on the subform and the filters used on the mainform.
When the query is correctly showing just the records showing in the
subform,
use Transfer Spreadsheet to put the data from the query into excel.
Use the vba help on Transfer Spreadsheet to set it up.
Transfer Spreadsheet is fairly simple to use.
Jeanette Cunningham -- Melbourne Victoria Australia
I have a Mainform where the user selection from one or a multiple of 4
comboboxes and select a date range. This information displays in a
subform.
I would like to use a Command Button on the Mainform to export the
information displayed in the subform to Excel. Suggestions Please.
Thanks