Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass parameter to query from form

Status
Not open for further replies.

Jean9

Programmer
Dec 6, 2004
128
US
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
 
Nevermind. It works when referencing [Forms]![FrmEC]![SFADMIN_FORM].[FORM]![SFECN_ITEMS].[Form]![ID] from the query, where SFADMIN_FORM is the name of the unbound object. The name of the nested subform object (SFECN_ITEMS) on SFECN which is what the unbound object's (SFADMIN_FORM) SourceObject is set to, was not SFECN_ITEMS. Once I changed it to SFECN_ITEMS, it worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top