473,806 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(TheDat e) 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 1303
Using your code:

function intMyResult(sta rtdate as date, enddate as date) as integer

'first get the date difference between the start date and the end date:
intDateCount = datediff(startd ate, 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*@deercreekc g.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(Ca mpStartDate,Cam pEndDate)

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(startd ate, 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
1978
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 not expected to check for everything. At any rate, the problem I am having with the following code is that it does not clear the fields once I press the SEND button. So can anyone here enlighten me as to what is causing the problem.
1
2566
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 the created records in the database and I don't want to lose all that info when I rename a file and synchronise, I've added some code to the program. It works like this: when the filename of a DB records
8
4942
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, System.EventArgs e) { MessageBox.Show("keyboard button pressed!"); } Following is the code to load the frmTestBaby
5
6297
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 client which is executed by the exe. I am facing problem while executing the exe on the remote machine. If I start the exe manually everything works fine but if I execute it remotely through code using WMI an exception is thrown saying "No...
12
2220
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 line which make the error is anchor but i cannot make it work. <TABLE id="tblDocList" dir="<%#strLangDir%>" style="DISPLAY:inline"
2
604
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 mail is sent fine. however every so often an error is reported where mail can't be sent. upon more closer inspection I find that the line that tries to send mail is throwing an error and the error generated is
3
1477
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
5052
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: <%@ Application Codebehind="Global.asax.vb" Inherits="<Namespace>." %> I've done a lot of things I've found on the web to no avial, but here are some unique things about what is happening to me.
8
13222
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 compiles & runs fine locally, but when I copy to the production machine, I get this error: Parser Error Message: Could not load type 'Global'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="Global" %> Source...
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10110
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.