Here is the code. It is called from a form. Thanks
Option Compare Database
Public Month_of_invoice As String
Public Year_of_invoice As String
Private Sub Command33_Click()
Select Case Frame0.Value
Case Is = 2
' This creates MS Excel files from the monthly budget data
' for the Denver database only, which operates in MS Access 2007
Dim strDefaultDir As String
Dim strFilter As String
Dim strInputFileName As String
Dim SQL As String
DoCmd.SetWarnings False ' turn warnings off
SQL = "SELECT [All Invoices].Code, Sum([All Invoices].Amount) AS
SumOfAMOUNT INTO [Monthly costs tracking] FROM [All Invoices]" & _
"GROUP BY [All Invoices].Code, [All Invoices].[Month invoice paid], [All
Invoices].[Year invoice paid], [All Invoices].[Sent to HSRC?]" & _
"HAVING ((([All Invoices].[Month invoice paid])=[Month_of_Invoice]) AND
(([All Invoices].[Year invoice paid])= [Year_of_Invoice]) AND (([All
Invoices].[Sent to HSRC?])=True));"
DoCmd.RunSQL SQL
' The following allows the user to save the Excel file to the directory
chosen by the user:
'Set up default path and file
strDefaultDir = "C:\Documents and Settings\My Documents\"
'Set up default file
strDefaultFileName = Month_of_invoice & Year_of_invoice & " monthly
expenses.xls"
'Set filter to show only Excel spreadsheets
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)")
'Flags Hides the Read Only Check and Only allow existing files
lngFlags = ahtOFN_HIDEREADONLY Or ahtOFN_OVERWRITEPROMPT
'Call the Open File Dialog
varGetFileName = ahtCommonFileOpenSave( _
Openfile:=False, _
InitialDir:=strDefaultDir, _
Filter:=strFilter, _
FileName:=strDefaultFileName, _
Flags:=lngFlags, _
DialogTitle:="Save Report")
If varGetFileName <> "" Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
"Monthly costs tracking", varGetFileName, True
End If
DoCmd.SetWarnings True ' turn warnings on
Msg2 = MsgBox("Your Excel file " & strDefaultFileName & " has been
created. Click OK to continue", vbInformation + vbOKOnly, "Excel File
Created")
Case Is = 3
DoCmd.Close acForm, "Monthly Expenses Summary"
DoCmd.OpenForm "Main", acNormal
End Select
End Sub
--
javablood
Klatuu said:
Post the code, please. Can't help troubleshoot something we can't see.
--
Dave Hargis, Microsoft Access MVP
:
I have a program in VBA in which I tried to run an SQL for which two
parameters (text) are entered by calling for them from the 'criteria' field.
I also want to use those same parameters as the front part of the name of a
file to save. However, no matter what I do (Public, Dim, etc) the portion of
the code that uses the parameters for the file name does not 'see' those
parameters. I have also tried forms to capture the parameters but have had
no luck there either? What am I doing wrong?
TIA