[blue]The following command button when clicked, saves the Query in Access and exports that Query to Excel.
I get a Run-Time Error '424' "Object Required".
I set A.BranchName as MSA_ARRAY(Iteration).Name
BranchName is what I want to pull from the Main SQL Query and save it as an Excel Worksheet with the worksheet name specified as BranchName Query. I want to save all BranchNames as separate worksheets in the same Excel File Path.[/blue]
Private Sub cmdExport_Click()
Dim ReportType As String
Dim Path As String
Dim SQL As String
Dim db As Database
Dim MSA_ARRAY
Dim Counter As Integer
Dim Iteration As Integer
ReportType = cboReport.Value
MSA_ARRAY = Array("Altamont", "Castanoan", "Blossom")
Counter = 0
Iteration = -1
Do While Counter <> 4
Counter = Counter + 1
Iteration = Iteration + 1
SQL = "SELECT A.PID, A.CID, A.month, A.contractyear, "
SQL = SQL & "A.[AM/SE], A.[members], A.[Final PMPM], "
SQL = SQL & "A.BranchName, B.Report"
SQL = SQL & " FROM tbl1 AS B INNER JOIN tbl2 AS A"
SQL = SQL & " ON B.BranchName = A.BranchName"
SQL = SQL & " WHERE B.Report='" & ReportType & "'"
SQL = SQL & " And A.month>=" & cboBegMonth.Value
SQL = SQL & " And A.month<=" & cboEndMonth.Value
SQL = SQL & " And A.contractyear>=" & cboBegYear.Value
SQL = SQL & " And A.contractyear<=" & cboEndYear.Value
SQL = SQL & " and A.BranchName=" & MSA_ARRAY(Iteration).Name
SQL = SQL & " Order by A.PID"
Set db = CurrentDb
db.CreateQueryDef MSA_ARRAY(Iteration).Name & " Query", SQL
Path = txtPath.Value
DoCmd.TransferSpreadsheet acExport, , MSA_ARRAY(Iteration).Name & " Query", "" & Path & "", True
Loop
MsgBox "All Branches are saved as " & Path, vbInformation
End Sub
I get a Run-Time Error '424' "Object Required".
I set A.BranchName as MSA_ARRAY(Iteration).Name
BranchName is what I want to pull from the Main SQL Query and save it as an Excel Worksheet with the worksheet name specified as BranchName Query. I want to save all BranchNames as separate worksheets in the same Excel File Path.[/blue]
Private Sub cmdExport_Click()
Dim ReportType As String
Dim Path As String
Dim SQL As String
Dim db As Database
Dim MSA_ARRAY
Dim Counter As Integer
Dim Iteration As Integer
ReportType = cboReport.Value
MSA_ARRAY = Array("Altamont", "Castanoan", "Blossom")
Counter = 0
Iteration = -1
Do While Counter <> 4
Counter = Counter + 1
Iteration = Iteration + 1
SQL = "SELECT A.PID, A.CID, A.month, A.contractyear, "
SQL = SQL & "A.[AM/SE], A.[members], A.[Final PMPM], "
SQL = SQL & "A.BranchName, B.Report"
SQL = SQL & " FROM tbl1 AS B INNER JOIN tbl2 AS A"
SQL = SQL & " ON B.BranchName = A.BranchName"
SQL = SQL & " WHERE B.Report='" & ReportType & "'"
SQL = SQL & " And A.month>=" & cboBegMonth.Value
SQL = SQL & " And A.month<=" & cboEndMonth.Value
SQL = SQL & " And A.contractyear>=" & cboBegYear.Value
SQL = SQL & " And A.contractyear<=" & cboEndYear.Value
SQL = SQL & " and A.BranchName=" & MSA_ARRAY(Iteration).Name
SQL = SQL & " Order by A.PID"
Set db = CurrentDb
db.CreateQueryDef MSA_ARRAY(Iteration).Name & " Query", SQL
Path = txtPath.Value
DoCmd.TransferSpreadsheet acExport, , MSA_ARRAY(Iteration).Name & " Query", "" & Path & "", True
Loop
MsgBox "All Branches are saved as " & Path, vbInformation
End Sub