To my mind, the "No table" handling belongs in the DeleteTable
function, not in the calling procedure. All the calling proc needs to
know is that the Table is gone when it gets control back
My actual code looks like
Cut & paste but with extra comments: '****
Sub DeleteTable(ByVal pstrTableName As String)
Const FNNAME As String = "basTableUtils.DeleteTable"
On Error GoTo ProcError
PushFunctionStack FNNAME
SetOwner pstrTableName, CurrentUser()
DoCmd.DeleteObject acTable, pstrTableName
DeleteTable = True
ProcExit:
On Error Resume Next
'******Put Cleanup code here
Exit Sub
ProcError:
Select Case Err.Number
case eAbort
'*******Special Handling goes here
Case eiTableNotFound
'Table doesn't exist, so we don't care
'*****End Special Handling
Case Else
HandleError Err.Number, FNNAME, Err.Source, Err.Description
Err.Raise eAbort 'Pass the error up the chain
End Select
Resume ProcExit
End Sub
This uses my standard error handler, and therefore has a number of
lines not used in this case. They are there because I use a tailored
EHT to generate the bones in EVERY procedure
In the days before EHT, I used to use an AutoKeys macro to achieve the
same end.
The Function Stack remembers the last 16 or so functions called, and
is written to a log along with any unexpected error. A great help in
tracking down elusive bugs.
I use
If fExitCondition then err.Raise eAbort '-------------------------->
whenever I want to exit a procedure early. so I keep the silent error
there all the time. This simplifies some otherwise very messy
constructs very nicely. I use the commented arrow to highlight exits.
I pass the Function Name to the error handler as the running function
is not necessarily the one at the top of the stack.
As a personal extension to the RVBA conventions:
e.... are all CUSTOM errors (Global Constants)
ei.... are internal Access errors that I am interested in. (ditto)
dtbl... are dynamic tables (Table definition can change)
zztbl... are temporary tables (Data can be cleared with impunity)
The first three are self explanatory in their origin.
The third was accidental, but it stuck.
I use the function as follows (with the error handler left out for
brevity)
Function MakeMyDynamicTable() as long
DeleteTable "dtblMine"
MakeMyDynamicTable = ExecuteSQL ("qmakMyDynamicTable")
end function
I trust this is suitalbly readable.
>
'Execute SQL returns the number of rows affected by the query,
'or -1 if it fails
Actually,
I very rarely use Make queries.
I prefer to Append into Temporary tables
That way I get to define the table my way without following up the
qmak with a bunch of TableDef stuff.
I am most likely to use dynamic tables as a recordsource for a Report
or Form instance (Where I have identical reports open, all showing
different data). Under these conditions, I copy a template table to
the dtbl, and still use a qapp.