Stemdriller
Registered User.
- Local time
- Today, 07:40
- Joined
- May 29, 2008
- Messages
- 187
I know this topic has been extensivley written about but I could do with some guidance.
I have a form with about 10 textboxes on. The first textbox gets it's date from the Release Date, less 30 days. The other textboxes get there dates from similar offsets off other textboxes cascading down.
eg Text2 = Text1 less 4 days
Text3 = Text less 5 days etc etc
And yes I need to omit weekends and holidays.
I am trying to get the following working
Public Function wdateadd(Startdate As Date, wdays As Integer)
Dim h As Integer
Dim w As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = Currentdb
Set rst = DB.OpenRecordset("SELECT [Date] FROM tblBankHoliday", dbOpenSnapshot)
w = 0
h = 0
Do Until h = wdays
mydate = DateAdd("d", w, Startdate)
rst.FindFirst "[Date] = #" & mydate & "#"
If Weekday(mydate) <> vbSunday And Weekday(mydate) <> vbSaturday Then
If rst.NoMatch Then
h = h + 1
End If
End If
w = w + 1
Loop
wdateadd = DateAdd("d", w, Startdate)
End Function
I have created a tblHolidays
My main issue is that I simply don't no how to implement this code.
I'm not particulary good with vba, i get by, just.
If one of you kind souls could explain how to get Text1 and Text2 working together I can then sort the rest out.
At your mercy
Gareth
I have a form with about 10 textboxes on. The first textbox gets it's date from the Release Date, less 30 days. The other textboxes get there dates from similar offsets off other textboxes cascading down.
eg Text2 = Text1 less 4 days
Text3 = Text less 5 days etc etc
And yes I need to omit weekends and holidays.
I am trying to get the following working
Public Function wdateadd(Startdate As Date, wdays As Integer)
Dim h As Integer
Dim w As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = Currentdb
Set rst = DB.OpenRecordset("SELECT [Date] FROM tblBankHoliday", dbOpenSnapshot)
w = 0
h = 0
Do Until h = wdays
mydate = DateAdd("d", w, Startdate)
rst.FindFirst "[Date] = #" & mydate & "#"
If Weekday(mydate) <> vbSunday And Weekday(mydate) <> vbSaturday Then
If rst.NoMatch Then
h = h + 1
End If
End If
w = w + 1
Loop
wdateadd = DateAdd("d", w, Startdate)
End Function
I have created a tblHolidays
My main issue is that I simply don't no how to implement this code.
I'm not particulary good with vba, i get by, just.
If one of you kind souls could explain how to get Text1 and Text2 working together I can then sort the rest out.
At your mercy
Gareth