I think following code will do:
'To find out No. of days between two dates excluing No. of Sundays in between them:
Dim StartDay As String
Private Sub Command1_Click()
If Me.DTPicker1.Value > Me.DTPicker2.Value Then
MsgBox "Please select Date FROM which is earlier than Date TO."
Exit Sub
End If
'StartDay = "vb" & Format(Me.DTPicker1.Value, "dddd") 'Used DTPicker3
StartDay = "vb" & Format(Me.DTPicker3.Value, "dddd")
start = Switch(StartDay = "vbSunday", 0, StartDay = "vbMonday", 1, StartDay = "vbTuesday", 2, StartDay = "vbWednesday", 3, StartDay = "vbThursday", 4, StartDay = "vbFriday", 5, StartDay = "vbSaturday", 6)
d = DateDiff("d", Me.DTPicker1.Value, Me.DTPicker2.Value, start)
'w = DateDiff("w", Me.DTPicker1.Value, Me.DTPicker2.Value, Start)
w = Fix(d / 7)
w1 = d - w * 7
If w1 <> 0 And d >= 7 Then w = w + 1 'if selcted more than 7 days and not full weeks then
Text1.Text = d - w
'MsgBox Day(Me.DTPicker2.Value)
'Text2.Text = Format(Me.DTPicker2.Value, "dddd") ' dd/mm/yyyy")'it is like Sunday or Monday etc.
End Sub
Private Sub DTPicker1_Change()
DTPicker3.Year = Me.DTPicker1.Year
Me.DTPicker3.Month = Me.DTPicker1.Month
Me.DTPicker3.Day = 1
'so that we can find out the first day of month in DTPicker1 from where we want
'to calculate the no. of days upto DTPicker2 (excluding Sundays).
End Sub
Private Sub Form_Load()
Text2.Visible = False
'During loading set DTPicker3 date as 1st of the month in DTPicker1.
DTPicker3.Year = Me.DTPicker1.Year
Me.DTPicker3.Month = Me.DTPicker1.Month
Me.DTPicker3.Day = 1
Me.DTPicker3.Visible = False
Command1_Click 'so that on loading No. of Days is shown.
End Sub
Always Believe in GOD!