I know this has probably been answered before but I can't seem to find it when I search for it. I have created a dummy subform (An unbound subform/subreport object that does not truly exist in the database) that I set the SourceObject on via code based on a combobox selection. Within the subform that loads, is nested subforms. On one of the nested subforms, I have included a command button for the user to export some data to excel. So, this used to work when the parent subform was an actual bound form on the main form and, from within the query, I referenced the sub sub form's control ([Forms]![FRMEC]![SFADMIN_FORM].[FORM]![SFECN_ITEMS].[Form]![ID] where the word SFADMIN_FORM used to be the actual bound form name - SFECN). NOW I am using SFADMIN_FORM as the dummy form that is an unbound object until I set the SourceObject. I've tried this with both SFADMIN_FORM and the name of the actual form that I am setting the SourceObject to (neither works). The code I am executing at _Click() is:
[code/]
Private Sub CmdEXP_2_XL_Click()
' Instantiate variable with file path and name
sFILENM = "C:\TEMP\ACTIONS LIST-" & Me.ITEM & "-" & Format(Now(), "YYYYMMDD" & "_" & "HHMM") & ".XLS"
' Create spreadsheet with query data
DoCmd.TransferSpreadsheet acExport, , "QryXL_ITEMS_ACTIONS", sFILENM
Set ObjXLApp = CreateObject("Excel.Application")
Set ObjXLBook = ObjXLApp.Workbooks.Open(sFILENM)
Set OSheet = ObjXLBook.Worksheets(1)
' Open worksheet
ObjXLApp.Visible = True
End Sub
[/code]
When this code runs now, the query, QryXL_ITEMS_ACTIONS, just prompts for the ([Forms]![FRMEC]![SFADMIN_FORM].[FORM]![SFECN_ITEMS].[Form]![ID] value.
What, in my query, do I need to use to reference the sub sub form's control when using an unbound object whose SourceObject is set at time of a combobox afterupdate event? Or if I can no longer do it this way, how can I pass QryXL_ITEMS_ACTIONS the parameter value on DoCmd.TransferSpreadsheet acExport?
Thanks in advance,
J9
[code/]
Private Sub CmdEXP_2_XL_Click()
' Instantiate variable with file path and name
sFILENM = "C:\TEMP\ACTIONS LIST-" & Me.ITEM & "-" & Format(Now(), "YYYYMMDD" & "_" & "HHMM") & ".XLS"
' Create spreadsheet with query data
DoCmd.TransferSpreadsheet acExport, , "QryXL_ITEMS_ACTIONS", sFILENM
Set ObjXLApp = CreateObject("Excel.Application")
Set ObjXLBook = ObjXLApp.Workbooks.Open(sFILENM)
Set OSheet = ObjXLBook.Worksheets(1)
' Open worksheet
ObjXLApp.Visible = True
End Sub
[/code]
When this code runs now, the query, QryXL_ITEMS_ACTIONS, just prompts for the ([Forms]![FRMEC]![SFADMIN_FORM].[FORM]![SFECN_ITEMS].[Form]![ID] value.
What, in my query, do I need to use to reference the sub sub form's control when using an unbound object whose SourceObject is set at time of a combobox afterupdate event? Or if I can no longer do it this way, how can I pass QryXL_ITEMS_ACTIONS the parameter value on DoCmd.TransferSpreadsheet acExport?
Thanks in advance,
J9