473,416 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Could use so code help!

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

Dec 12 '05 #1
5 1289
Using your code:

function intMyResult(startdate as date, enddate as date) as integer

'first get the date difference between the start date and the end date:
intDateCount = datediff(startdate, enddate)

'then loop through the dates and count the number of holiday days
dim dtTemp as date
dim intHolCount as integer

intHolCount = 0
dtTemp = startdate

Do while not dtTemp > enddate
if DiscRate then intHolCount = intHolCount + 1
dtTemp = dateserial(year(dtTemp), month(dtTmp), day(dtTemp) +1)
loop

'now subtract the two for your result
intMyResult = intDateCount - intHolCount

End Function

But this slow and nasty if there's a large date gap - there'll be a
bottle neck at the dlookup in the DiscRate function... especially if
you have a split database.
My advice: Produce a table of working days and do a count query on it
based on accepting the dates as paramaters - there's lots on
paramaterised queries elsewhere.

Dec 12 '05 #2
> if DiscRate then intHolCount = intHolCount + 1

sorry, that should be:
if DiscRate(dtTemp) then intHolCount = intHolCount + 1

dooh!

Dec 12 '05 #3
I'm a little slow but, I don't see how this is accoplishing what I'm
after? I need it to send a nuber of days staying that are not a weekend
or a holiday. Based on 2 fields that I have in my form my start and end
dates.

Dec 12 '05 #4
On 12 Dec 2005 09:18:38 -0800, "deercreek" <da*@deercreekcg.com>
wrote:
I'm a little slow but, I don't see how this is accoplishing what I'm
after? I need it to send a nuber of days staying that are not a weekend
or a holiday. Based on 2 fields that I have in my form my start and end
dates.


What you want to do is type (well, cut and paste would be easier) what
Bill gave you right next to the function that you already have (either
below it or above it).

Then, in the textbox that you want to see the "result" displayed in,
change the controlsource to:

=intMyResult(CampStartDate,CampEndDate)

Then type something into CampStartDate and CampEndDate and see what
ends up in your textbox.

But there are 3 corrections to Bill's code that are needed:

1) Add

Dim intDateCount as Integer

as the first line of intMyResult

2) Change Month(dtTmp) to Month(dtTemp) on the line just above the
Loop command

3) Change

intDateCount = DateDiff(startdate, enddate)

to

intDateCount = DateDiff("d", startdate, enddate)

That should do it.

This will give you "#error" in your textbox unless or until both the
dates are filled in. If you want to see something other than "#error"
then you need to add some error checking to Bill's routine.

mike
Dec 12 '05 #5
Thanks Mike,

The code was meant more as a guidline, but I got a little sloppy there,
must have been too much blood in my coffee stream - sorry deercreed!!!
I really should hit preview before I post
8¬/

Dec 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sue | last post by:
Hello! I am back with another question. Remember I am a new JavaScript student and I am aware that this code does not check for all the possibilities and that as a "NEW" JavaScript student I am...
1
by: Koen | last post by:
Hi all, I created a little database to manage my e-books. The program will synchronize a table with the contents of a directory. Works great. Because I keep additional info (like keywords) to...
8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
5
by: Data | last post by:
In my project I want to execute some commands on the remote machine. I am using .Net Remoting to achieve this. My server which is an exe is copied on the remote machine and it receives command from...
12
by: Raed Sawalha | last post by:
I have the following table which i can not switcha to design view error message said Could not open in Design view. Quote values differently inside a '<% ...."value"... %>' block. and the...
2
by: Martin | last post by:
Hi, I have standard code that sends mail from an asp.net application. The application is running on a production web server. it uses the standard system.web.mail namespace. most of the time...
3
by: mslyman | last post by:
Hi, I could do with some help. I have this XML. <region> <region_code>567</region_code> <store> <store_code>345</store_code> <dept> <dept_code>32</dept_code> </dept>
16
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.