Passing arguments to procedures
- From: Peter Hallett <PeterHallett@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Mar 2008 05:02:00 -0800
There is something fundamental that I have failed to grasp about passing
arguments to procedures.
I have a form featuring a set of unbound controls displaying dates and the
corresponding days of the week. (For some reason, the long-date format, on
my computer, does not include the latter, as the documentation suggests it
might, so it has to be separately calculated and displayed.)
A default date is displayed in each control, on Form_Open. This can then be
manually adjusted by a pair of ‘up’ and ‘down’ buttons associated with each
day/date control pair. In the case of the control ‘Start_Date’, for example,
the first two procedures are specific to the control, whilst the third Sub
and the following Function are common to the form.
Private Sub ComDateStartNext_Click() ‘Increment date by one day
IncDecDateDay Me.StartDate, Me.StartDay, 1
End Sub
Private Sub ComDateStartPrevious_Click() ‘Decrement date by one day
IncDecDateDay Me.StartDate, Me.StartDay, -1
End Sub
Private Sub IncDecDateDay(InDate, InDay, ByVal Increment As Integer)
InDate = InDate + Increment
InDay = Get_WeekDay(InDate)
End Sub
Private Function Get_WeekDay(InDate) As String
Select Case Weekday(InDate)
Case 1
Get_WeekDay = "SUN"
Case 2
Get_WeekDay = "MON"
Case 3
Get_WeekDay = "TUE"
Case 4
Etc.
End Select
End Function
Nothing happens when the ‘up’ and ‘down’ buttons are clicked but if I
replace the implicit general-purpose Sub IncDecDateDay with the explicit test
version:–
Private Sub IncDecDateDay(InDate, InDay, ByVal Increment As Integer)
Me.StartDate = InDate + Increment
Me.StartDay = Get_WeekDay(InDate)
End Sub
....it all works fine (in the case of the ‘Start_Date’ control, of course)
but my belief that changes to the parameter InDate would be reflected in the
displayed value of the original calling control are clearly wrong. It is not
that I cannot find an alternative solution – I can recast the thing using a
function to return the required values – but what worries me is that I have
obviously been labouring under a misapprehension. Perhaps I spent too long
messing about with ‘C’. Would someone be kind enough to enlighten me?
---Peter Hallett
.
- Follow-Ups:
- Re: Passing arguments to procedures
- From: Brendan Reynolds
- Re: Passing arguments to procedures
- Prev by Date: Re: FindAsUType I got it to work but still have ?
- Next by Date: Re: to Filter or not to Filter option not working...
- Previous by thread: Re: VBA in the form for 2 kinds of membership
- Next by thread: Re: Passing arguments to procedures
- Index(es):
Relevant Pages
|