A
Ant
Hi
I have the following code with an error handling in one part of the code.
Once the For...Next loop has finished running a macro is called and then
after it should stop (by going into the Exit_Adhoc_Click and then exiting).
However it seems to ignore the Exit_Adhoc_Click and then going into the
Err_Monthly_Click.
I can't seem to work out why this is happening. (I have missed out some of
the code that would be overkill, I don't think it is relevant to the problem
Thanks in advance
Private Sub Monthly_Click()
Dim NumCarr As Integer
Let NumCarr = DCount("*", "Qry_5_1_1_Carrier_Numbered")
Dim Month As Date
Dim monthnum As String
Let Forms![Fm_2_Import_Rates]![Entry_Indicator] = "M"
monthnum = Forms![Fm_2_Import_Rates]![Month_Select]
If monthnum = 0 Then
randvar = MsgBox("Please select a month from the drop down box")
Exit Sub
End If
Month = Format("01/" & Right(monthnum, 2) & "/" & Left(monthnum, 4),
"dd/mm/yy")
For N = 1 To NumCarr
Dim qd As DAO.Querydef
Set qd = currentdb.CreateQuerydef(strName, strSQL)
On Error GoTo Err_Monthly_Click
DoCmd.OpenQuery ("QueryX")
DoCmd.DeleteObject acQuery, "QueryX"
DoCmd.DeleteObject acQuery, "QueryY"
DoCmd.SetWarnings True
Next N
DoCmd.RunMacro "Mc_2_Import_Rates.Duplicates"
DoCmd.SetWarnings True
Exit_Monthly_Click:
Exit Sub
Err_Monthly_Click:
randvar = MsgBox("You have a carrier " & Carr & " in the database and
not in the import file. Either add to the import file or delete from the
database", vbOKOnly)
randvar = MsgBox("No rates were imported")
DoCmd.DeleteObject acQuery, "QueryX"
DoCmd.DeleteObject acQuery, "QueryY"
DoCmd.OpenQuery ("Qry_1_1_1_Delete_Import_Table")
DoCmd.SetWarnings True
Resume Exit_Monthly_Click
End Sub
I have the following code with an error handling in one part of the code.
Once the For...Next loop has finished running a macro is called and then
after it should stop (by going into the Exit_Adhoc_Click and then exiting).
However it seems to ignore the Exit_Adhoc_Click and then going into the
Err_Monthly_Click.
I can't seem to work out why this is happening. (I have missed out some of
the code that would be overkill, I don't think it is relevant to the problem
Thanks in advance
Private Sub Monthly_Click()
Dim NumCarr As Integer
Let NumCarr = DCount("*", "Qry_5_1_1_Carrier_Numbered")
Dim Month As Date
Dim monthnum As String
Let Forms![Fm_2_Import_Rates]![Entry_Indicator] = "M"
monthnum = Forms![Fm_2_Import_Rates]![Month_Select]
If monthnum = 0 Then
randvar = MsgBox("Please select a month from the drop down box")
Exit Sub
End If
Month = Format("01/" & Right(monthnum, 2) & "/" & Left(monthnum, 4),
"dd/mm/yy")
For N = 1 To NumCarr
Dim qd As DAO.Querydef
Set qd = currentdb.CreateQuerydef(strName, strSQL)
On Error GoTo Err_Monthly_Click
DoCmd.OpenQuery ("QueryX")
DoCmd.DeleteObject acQuery, "QueryX"
DoCmd.DeleteObject acQuery, "QueryY"
DoCmd.SetWarnings True
Next N
DoCmd.RunMacro "Mc_2_Import_Rates.Duplicates"
DoCmd.SetWarnings True
Exit_Monthly_Click:
Exit Sub
Err_Monthly_Click:
randvar = MsgBox("You have a carrier " & Carr & " in the database and
not in the import file. Either add to the import file or delete from the
database", vbOKOnly)
randvar = MsgBox("No rates were imported")
DoCmd.DeleteObject acQuery, "QueryX"
DoCmd.DeleteObject acQuery, "QueryY"
DoCmd.OpenQuery ("Qry_1_1_1_Delete_Import_Table")
DoCmd.SetWarnings True
Resume Exit_Monthly_Click
End Sub