J
Jânio T via AccessMonster.com
Hi all,
I have the following 'problem'. For statistical analyses I needs soms data
in Excel. The data is build up with 2 crosstab querries.
If I run the querries from the query screen than they do exactly what they
need to do, but if I run them with my vba on click event only the first
crosstab is executed and the second one gives me error : ' To create a
crosstab query, you must specify one or more Row Heading(s) options, one
Column Heading option, and one Value option. "
My code is:
Private Sub cmdExprExcel_Click()
Dim qdA As DAO.QueryDef
Dim qdC As DAO.QueryDef
Dim sSQL As String
Dim sWherestring As String
On Error GoTo Err_cmdExprExcel_Click
On Error Resume Next
DoCmd.OpenForm "frmPleaseWait", acNormal
If IsNull(Me.cmbFrom) Or IsNull(Me.cmbUntill) Then
MsgBox "Please fill in both the from and the untill year", vbInformation,
"Cas Report"
Else
If (Me.cmbFrom) > (Me.cmbUntill) Then
MsgBox "Then untill year can't be earlier the the from year",
vbInformation, "Cas Report"
Else
sWherestring = " (((CAS_OWNER_CURSIST_CURSUS_VIEW.JAAR)>=" & Me.
cmbFrom
sWherestring = sWherestring & " And (CAS_OWNER_CURSIST_CURSUS_VIEW.
JAAR)<=" & Me.cmbUntill & "));"
Set qdA = CurrentDb().QueryDefs("qry_totaalAanvragenPerJaar_vb")
sSQL = qdA.SQL
sSQL = Left$(sSQL, ((Len(sSQL)) - 3))
sSQL = sSQL & " HAVING" & sWherestring
Set qdA = CurrentDb().QueryDefs("qry_totaalAanvragenPerJaar")
qdA.SQL = sSQL
Set qdC = CurrentDb().QueryDefs("qry_TotaalCursistenPerJaar_vb")
sSQL = qdC.SQL
sSQL = Left$(sSQL, ((Len(sSQL)) - 3))
sSQL = sSQL & " AND" & sWherestring
Set qdC = CurrentDb().QueryDefs("qry_TotaalCursistenPerJaar")
qdC.SQL = sSQL
Set qdA = Nothing
Set qdC = Nothing
'qdA.Close
'qdC.Close
'DoCmd.OutputTo acOutputQuery, "qry_TotaalAanvragenPerJaar_Crosstab",
acFormatXLS, "Total_applicants" & Date & ".xls", True
DoCmd.OutputTo acOutputQuery, "qry_TotaalCursistenPerJaar_Crosstab",
acFormatXLS, "Total_Students" & Date & ".xls", True
End If
End If
Exit_cmdExprExcel_Click:
DoCmd.Close acForm, "frmPleaseWait"
Exit Sub
Err_cmdExprExcel_Click:
MsgBox Err.Description
Resume Exit_cmdExprExcel_Click
End Sub
The second query (which is not running in VBA ) is:
TRANSFORM Sum(qry_TotaalCursistenPerJaar.Total) AS SumOfTotal
SELECT qry_TotaalCursistenPerJaar.JAAR, Sum(qry_TotaalCursistenPerJaar.Total)
AS [Total Number]
FROM qry_TotaalCursistenPerJaar
GROUP BY qry_TotaalCursistenPerJaar.JAAR
PIVOT qry_TotaalCursistenPerJaar.NAAM;
Thankx in advance
I have the following 'problem'. For statistical analyses I needs soms data
in Excel. The data is build up with 2 crosstab querries.
If I run the querries from the query screen than they do exactly what they
need to do, but if I run them with my vba on click event only the first
crosstab is executed and the second one gives me error : ' To create a
crosstab query, you must specify one or more Row Heading(s) options, one
Column Heading option, and one Value option. "
My code is:
Private Sub cmdExprExcel_Click()
Dim qdA As DAO.QueryDef
Dim qdC As DAO.QueryDef
Dim sSQL As String
Dim sWherestring As String
On Error GoTo Err_cmdExprExcel_Click
On Error Resume Next
DoCmd.OpenForm "frmPleaseWait", acNormal
If IsNull(Me.cmbFrom) Or IsNull(Me.cmbUntill) Then
MsgBox "Please fill in both the from and the untill year", vbInformation,
"Cas Report"
Else
If (Me.cmbFrom) > (Me.cmbUntill) Then
MsgBox "Then untill year can't be earlier the the from year",
vbInformation, "Cas Report"
Else
sWherestring = " (((CAS_OWNER_CURSIST_CURSUS_VIEW.JAAR)>=" & Me.
cmbFrom
sWherestring = sWherestring & " And (CAS_OWNER_CURSIST_CURSUS_VIEW.
JAAR)<=" & Me.cmbUntill & "));"
Set qdA = CurrentDb().QueryDefs("qry_totaalAanvragenPerJaar_vb")
sSQL = qdA.SQL
sSQL = Left$(sSQL, ((Len(sSQL)) - 3))
sSQL = sSQL & " HAVING" & sWherestring
Set qdA = CurrentDb().QueryDefs("qry_totaalAanvragenPerJaar")
qdA.SQL = sSQL
Set qdC = CurrentDb().QueryDefs("qry_TotaalCursistenPerJaar_vb")
sSQL = qdC.SQL
sSQL = Left$(sSQL, ((Len(sSQL)) - 3))
sSQL = sSQL & " AND" & sWherestring
Set qdC = CurrentDb().QueryDefs("qry_TotaalCursistenPerJaar")
qdC.SQL = sSQL
Set qdA = Nothing
Set qdC = Nothing
'qdA.Close
'qdC.Close
'DoCmd.OutputTo acOutputQuery, "qry_TotaalAanvragenPerJaar_Crosstab",
acFormatXLS, "Total_applicants" & Date & ".xls", True
DoCmd.OutputTo acOutputQuery, "qry_TotaalCursistenPerJaar_Crosstab",
acFormatXLS, "Total_Students" & Date & ".xls", True
End If
End If
Exit_cmdExprExcel_Click:
DoCmd.Close acForm, "frmPleaseWait"
Exit Sub
Err_cmdExprExcel_Click:
MsgBox Err.Description
Resume Exit_cmdExprExcel_Click
End Sub
The second query (which is not running in VBA ) is:
TRANSFORM Sum(qry_TotaalCursistenPerJaar.Total) AS SumOfTotal
SELECT qry_TotaalCursistenPerJaar.JAAR, Sum(qry_TotaalCursistenPerJaar.Total)
AS [Total Number]
FROM qry_TotaalCursistenPerJaar
GROUP BY qry_TotaalCursistenPerJaar.JAAR
PIVOT qry_TotaalCursistenPerJaar.NAAM;
Thankx in advance