Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / December 2005

Tip: Looking for answers? Try searching our database.

Could use so code help!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
deercreek - 12 Dec 2005 16:24 GMT
I could use a little help from a good code writer out there. I found
some code and modified it a bit for my needs but, I need a little help
to finish it up. What I am trying to due is to get a number to fill out
a text box on my form. I want it to look at the form and get the
CampStartDate and my CampEndDate also to look at a table of holidays.
Then I want the text box to be filled with the number of days they will
be staying that do not fall on a fri sat or sun or holiday. The code I
have below is able to look at single date and determine if it is a fri,
sat, sun or holiday. When it is it returns a -1 value. I would like
to incorporate this code to do what I asked above. It's just a little
out of my league. Anyone that could help I would appreciate it.

Code

Option Compare Database

Function DiscRate(TheDate) As Integer

  DiscRate = False
    TheDate = Format(TheDate, "dd/mm/yyyy")
  ' Test for Friday, Saturday or Sunday.
  If WeekDay(TheDate) = 6 Or WeekDay(TheDate) = 7 Or WeekDay(TheDate)
= 1 Then
      DiscRate = True
  ' Test for Holiday.
  ElseIf Not IsNull(DLookup("HoliDate", "Holidays", "[HoliDate]=#" _
  & TheDate & "#")) Then
      DiscRate = True
  End If

End Function

Thanks
Dan
Graham Mandeno - 12 Dec 2005 22:40 GMT
Hi Dan

Try using this function:

Public Function CountCampDays( _
   dtStart As Date, _
   dtEnd As Date) _
   As Integer
Const cDateFormat = "\#mm\/dd\/yyyy\#"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim iCount As Integer
Dim dtNext As Date
On Error GoTo ProcErr
 Set db = CurrentDb
 Set rs = db.OpenRecordset("Select HoliDate From Holidays " _
   & "where HoliDate between " & Format(dtStart, cDateFormat) _
   & " and " & Format(dtEnd, cDateFormat))
 For dtNext = dtStart To dtEnd
   If Weekday(dtNext, vbMonday) < 5 Then
     rs.FindFirst "HoliDate=" & Format(dtNext, cDateFormat)
     If rs.NoMatch Then iCount = iCount + 1
   End If
 Next
 CountCampDays = iCount
ProcEnd:
 On Error Resume Next
 rs.Close
 Set rs = Nothing
 Set db = Nothing
 Exit Function
ProcErr:
 MsgBox Err.Description
 Resume ProcEnd
End Function

Some tricks to note:

1. Weekday(dtNext, vbMonday) starts counting the weekday from Monday, so you
just need to check for <5 instead of =6 or =7 or =1

2. Opening a recordset of holidays between the two dates is much more
efficient than doing a whole series of DLookups.

3. Whenever you compare dates in SQL (including FindFirst and DLookup etc)
you must use the American dat e format (mm/dd/yyyy).  Your code is using
dd/mm/yyyy and will not work.
Signature

Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

>I could use a little help from a good code writer out there. I found
> some code and modified it a bit for my needs but, I need a little help
[quoted text clipped - 30 lines]
> Thanks
> Dan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.