Databases Reference
In-Depth Information
frmDateTime.OptionButton_TimeMil = True
Call OptionButton_YYYY_Click
frmDateTime.OptionButton_YYYY = True
Call OptionButton_MonthNumb_Click
frmDateTime.OptionButton_MonthNumb = True
OptionButton_OrderYMD.Value = True
frmDateTime.CheckBox_MonthILZ.Value = True
frmDateTime.CheckBox_NoSpaces.Value = True
Call OptionButton_SepUndscr_Click
End Sub
Although this code seems simple and straightforward enough, there are some things here worth
calling attention to. Of particular noteworthiness is how the string that comprises the Format
statement for the date is constructed. When this application was first constructed, instead of utilizing
the Format function to return each date component individually like this:
yc = Format(Date, "yyyy")
it was thought that the string utilized to return the date in the format desired could be constructed
like this:
yc = "yyyy"
Then each of the three string components could be concatenated together within the Format
function to produce the date required in a manner like this:
FormatString$ = yc & mc & dc
Dummy$ = Format(Date, FormatString$)
Unfortunately, such a scheme does not work when dumping the result of the Format function
into a textbox within a GUI. What ends up happening is that Excel will insert “\” marks within
the date thinking it is “helping” you. Ordinarily, this would not be a big deal, but if the date-time
stamp is to be utilized as a filename, this behavior is catastrophic. If the result of the format
statement were not to be written to a textbox but a string variable within the macro, such a scheme
would work just fine (no additional “\”'s would be added). It is unforeseen pitfalls like these that
eat up extraordinary amounts of a programmer's time.
When a check box is selected on the form that changes settings defined by option buttons, it is
necessary to call the code associated with selected option button's click event in order to process the
change associated with check box. For example, if the “Include Leading Zero” checkbox in the month
frame is changed within the GUI, it is necessary to call the code associated with the option button labeled
“Number” for a leading zero to be included or omitted when the month is to be specified in a numerical
format. This is done in the Private Sub CheckBox_MonthILZ_Click() subroutine.
Similarly, it is worth mentioning that when a form is loaded, even if some option buttons and check
boxes have their values set to True (or selected as the defaults at design time), the component variables
for the date and time (yc, mc, dc, tc) will not be set unless the resultant code is executed within the click
event that corresponds to the option buttons and check boxes associated with the date and time variable
components (yc,mc,dc,tc). It is also important to note that if the click event for a check box or option
button is run from code, it does not result in the option button or check box being selected or deselected
as it would have if the user would have clicked the control on the form. (This is really counterintuitive.)
The only way to set an objects state from code is to change its Value property to True. The default
settings for the form in this example are set in the UserForm_Initialize subroutine.
One final point concerns the initialization of objects on a form. This can be accomplished in
one of two manners utilizing either the Initialize Event or the Activate Event. It is
Search WWH ::




Custom Search