No, it's in the Sub or Function header. There are several ways to implement
optional arguments, but essentially you just declare the argument as
Optional. Depending on the declared data type of the argument, it will have
a predefined value if it wasn't specified: numeric types have a value of 0,
string arguments have a value of "" (zero-length string), and Variant
arguments get a special value indicating that the argument is missing. You
can also specify in the declaration of the argument what value you want it
to have if the caller doesn't pass it, overriding the default for the data
type.
For your purposes, it's probably simplest if you use a numeric argument
specifying the step you want to start with, and allow the default value of 0
to indicate that you should start at the begining. If you currently have a
Sub procedure named DoMyStuff, you might declare it like this:
Sub DoMyStuff(Optional StartStep As Integer)
It isn't clear to me how you intend to invoke the procedure in the first
place. If this is something you are just doing manually and have no form
event to trigger it (like clicking a command button), you can always invoke
it from the Immediate Window. You would press Ctrl+G if necessary to open
the Immediate Window, and enter the procedure call there:
DoMyStuff 3
Here's an example of how the procedure might look:
'------ start of example code ------
Sub DoMyStuff(Optional StartStep As Integer)
On Error GoTo Err_Handler
Dim strSQL As String
Dim intCurrStep
' Step1: QM_High_School
intCurrStep = 1
If StartStep <= intCurrStep Then
strSQL = _
"SELECT T_Fall_Admits.SARADAP_PIDM INTO T_High_School" & _
" FROM T_Fall_Admits
DoCmd.RunSQL strSQL
End If
' Step2: QM_Legacy_Admits
intCurrStep = 2
If StartStep <= intCurrStep Then
strSQL = _
"SELECT T_Admits.SARAPPD_PIDM " & _
" FROM T_Admits ;"
'*** NOTE: THE ABOVE SQL IS NOT VALID,
'*** THOUGH IT IS WHAT YOU POSTED.
'*** YOU CAN'T "RUNSQL" A SELECT QUERY.
'*** THIS SHOULD PROBABLY BE AN APPEND QUERY.
DoCmd.RunSQL strSQL
End If
Exit_Point:
Exit Sub
Err_Handler:
MsgBox _
"An error occurred in step " & intCurrStep & _
". The error message was:" & vbCr & vbCr & _
Err.Description & _
vbCr & vbCr & "The current SQL statement was:" & _
vbCr & vbCr & strSQL, _
vbExclamation, _
"Error " & Err.Number
Resume Exit_Point
End Sub
'------ end of example code ------
Does that make the approach clear? Note that the above procedure only has
two steps, so "DoMyStuff 3" doesn't really make sense with that version.
--
Dirk Goldgar, MS Access MVP
Access tips:
www.datagnostics.com/tips.html
(please reply to the newsgroup)