Why is Error Handling running when there's no error

catbeasy

Registered User.
Local time
Today, 09:29
Joined
Feb 11, 2009
Messages
140
The error handle part of the code runs even though there is no error (I rem'd out the error handling to make sure there was no error)..Everything under: error_esc: runs. And, of course, since there's no error, the msgbox's that are supposed to show an error description are blank..

Is my syntax incorrect? Here is the code. Thanks for any assistance..

Private Sub cmd_export_to_excel_Click()
On Error GoTo error_esc
Dim fp As String
Dim fn As String
Dim exp_obj_name As String
Dim qrydefObj As QueryDef
Dim varItem As Variant
Dim strTemp As String
Dim strSQL As String
Dim strSQL_Combine As String
Dim qdf As DAO.QueryDef
Dim qry_name As String
qry_name = "qry_rpt_ct_source"

If Me.lst_Loc.ItemsSelected.Count = 0 Then
DoCmd.Hourglass False
MsgBox "You have not selected a Location or Locations for the report. Please Select a Location."
ElseIf Me.lst_Loc.ItemsSelected.Count > 0 Then
'clear crosstab table
CurrentDb.Execute "DELETE * from tbl_Rpt_Crosstab_Prep"

DoCmd.Hourglass True
Call Build_Cross_Tab_Prep 'appends tbl_data data to the crosstab prep table so that a crosstab query can be used with the data..
Call update_goal 'updates the goals into the crosstab prep table..



'code below builds the query that the crosstab queries will read. criteria is set for the state by these created queries..
For Each varItem In Me.lst_Loc.ItemsSelected
strTemp = strTemp & "(tbl_Rpt_Crosstab_Prep.STATE)= " & "'" & Me.lst_Loc.ItemData(varItem) & "' Or "
Next varItem
strTemp = Left(strTemp, Len(strTemp) - 4)
str_qry_cri_state = strTemp
strSQL = "select * from tbl_Rpt_Crosstab_Prep WHERE (("
strSQL_Combine = strSQL & str_qry_cri_state & "))"
For Each qdf In CurrentDb.QueryDefs
Debug.Print qdf.Name
If qdf.Name = qry_name Then
CurrentDb.QueryDefs.Delete (qry_name)
End If
Next

'set the query to the appropriate sql statement. criteria is built by selections on the reporting form..
Set qrydefObj = CurrentDb.CreateQueryDef(qry_name, strSQL_Combine)

'.now, export the data in the crosstab queries to drive as an excel object
'fp = "Z:\GoldPointe\MemAcct\Martin_Benson\Martin\Projects\Mbrship_Metrics\output\"
fp = "I:\"

If Me.fra_rpt_sel = 1 Then 'cumulative view
fn = "Mbrship_Metrics_View_Cumulative_" & Format(Now, "yyyymmddhhnnss") & ".xls"
exp_obj_name = "qry_Rpt_CT_By_Cumulative"
ElseIf Me.fra_rpt_sel = 2 Then 'by month
fn = "Mbrship_Metrics_View_Month_" & Format(Now, "yyyymmddhhnnss") & ".xls"
exp_obj_name = "qry_Rpt_CT_By_Month"
ElseIf Me.fra_rpt_sel = 3 Then 'by quarter
fn = "Mbrship_Metrics_View_Quarter_" & Format(Now, "yyyymmddhhnnss") & ".xls"
exp_obj_name = "qry_Rpt_CT_By_Quarter"
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, exp_obj_name, fp & fn, True
DoCmd.Hourglass False
MsgBox "Done!"
End If

error_esc:
DoCmd.Hourglass False
MsgBox Err.Description
MsgBox Err.Source

End Sub
 
You haven't told it otherwise. You need

Exit Sub

before the error trap.
 

Users who are viewing this thread

Back
Top Bottom