Getting Raskew's code to work dynamically (1 Viewer)

mdnuts

Registered User.
Local time
Today, 15:21
Joined
May 28, 2014
Messages
128
I'm following this
which works fantastically if I put in what the example says to

Code:
to call ? NthXDay(dateserial(year(date), 1, 1),vbMonday, 3)
But I need to set that dynamically. DateSerial part is no problem, it is the vb(Dayofweek) and the Nth of that day that I cannot get to work.

Breaking it out like this.
Code:
       strMonthDay = "vb" & Me.cboMonthDay
       strMonthWeekNum = Int(Left(Me.cboMonthWeekNum, Len(Me.cboMonthWeekNum) - 2))
       MsgBox NthXDay(DateSerial(Year(Date), Month(Date), 1), strMonthDay, strMonthWeekNum)
The above is selected by the user who picks 1st, 2nd, 3rd, 4th in one drop down and Monday, Tuesday, etc in another drop down on the form.

What I get in error is
ByRef argument type mismatch
Which tells me it is passing as a string and needs to pass as something else - such as Integer. I've tried dim the two variables as integer and they just give a type mismatch.

As reference - here is the function declaration used
Code:
Function NthXDay(pdate As Variant, pWDay As Integer, _ pIncrement As Integer) As Date 'coded by:  raskew
Any ideas?
 

TJPoorman

Registered User.
Local time
Today, 13:21
Joined
Jul 23, 2013
Messages
402
The problem is that vbMonday is not a string, it is an enumeration.
The values are:
vbSunday - 1
vbMonday - 2
vbTuesday - 3
vbWednesday - 4
vbThursday - 5
vbFriday - 6
vbSaturday - 7

You would ultimately need a case statement to determine the day, then translate that to a number.
 

mdnuts

Registered User.
Local time
Today, 15:21
Joined
May 28, 2014
Messages
128
Thank you, that did it.
 

Users who are viewing this thread

Top Bottom