473,795 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unclear how to perform this action in Access. Help needed if possible.

55 New Member
Hello all. I am very new to this and I don't know if VBA is the better route to go.

First and foremost I am running Access 2003.

I have a table in my Access database. This table is made up of three fields. The first being Date. The second being Day of the Week (ie. Sunday, Monday, etc.) and the third being holiday/weekend. Under the column holiday/weekend I have inputted a "Y" if it is a weekend or holiday; Else, I have a null value.

In another table, I have my daily earnings for Monday - Friday. On Friday, my daily earnings will carry forward through the weekend/holiday. For instance, I earned $100 dollars on Friday, which means I will earn $100 on Saturday, Sunday or even a holiday.

I do not know how to write the code to project for the weekend.
Below is what I believe the code for determining the weekend/holiday.

Any help would be greatly appreciated as I am extremely confused.

Public Function AddWorkDays(Ori ginalDate As Date, DaysToAdd As Integer) As
Date
'OriginalDate = First Day to calculate number of working days from
'DaysToAdd = Number of Working Days to add to OriginalDate
'Returns the date that is the last working day for the number of days
'To look back, pass a negative number of days
'If 0 is entered, the current date is returned
Dim intDayCount As Integer
Dim dtmReturnDate As Date
Dim intAdd As Integer
'Determine whether to add or subtract
Select Case DaysToAdd
Case Is >= 1
intAdd = 1
Case Is = 0
AddWorkDays = OriginalDate
Exit Function
Case Else
intAdd = -1
End Select
intDayCount = 0
Do While True
If Weekday(Origina lDate, vbMonday) <= 5 Then 'It is a weekday
If IsNull(DLookup( "[Date]", "Holidays", _
"[Date] = #" & OriginalDate & "#")) Then
intDayCount = intDayCount + intAdd
dtmReturnDate = OriginalDate
End If
End If
If intDayCount = DaysToAdd Then
Exit Do
End If
OriginalDate = DateAdd("d", intAdd, OriginalDate)
Loop
AddWorkDays = dtmReturnDate
End Function
Dec 19 '07 #1
2 1548
MikeTheBike
639 Recognized Expert Contributor
Hello all. I am very new to this and I don't know if VBA is the better route to go.

First and foremost I am running Access 2003.

I have a table in my Access database. This table is made up of three fields. The first being Date. The second being Day of the Week (ie. Sunday, Monday, etc.) and the third being holiday/weekend. Under the column holiday/weekend I have inputted a "Y" if it is a weekend or holiday; Else, I have a null value.

In another table, I have my daily earnings for Monday - Friday. On Friday, my daily earnings will carry forward through the weekend/holiday. For instance, I earned $100 dollars on Friday, which means I will earn $100 on Saturday, Sunday or even a holiday.

I do not know how to write the code to project for the weekend.
Below is what I believe the code for determining the weekend/holiday.

Any help would be greatly appreciated as I am extremely confused.

Public Function AddWorkDays(Ori ginalDate As Date, DaysToAdd As Integer) As
Date
'OriginalDate = First Day to calculate number of working days from
'DaysToAdd = Number of Working Days to add to OriginalDate
'Returns the date that is the last working day for the number of days
'To look back, pass a negative number of days
'If 0 is entered, the current date is returned
Dim intDayCount As Integer
Dim dtmReturnDate As Date
Dim intAdd As Integer
'Determine whether to add or subtract
Select Case DaysToAdd
Case Is >= 1
intAdd = 1
Case Is = 0
AddWorkDays = OriginalDate
Exit Function
Case Else
intAdd = -1
End Select
intDayCount = 0
Do While True
If Weekday(Origina lDate, vbMonday) <= 5 Then 'It is a weekday
If IsNull(DLookup( "[Date]", "Holidays", _
"[Date] = #" & OriginalDate & "#")) Then
intDayCount = intDayCount + intAdd
dtmReturnDate = OriginalDate
End If
End If
If intDayCount = DaysToAdd Then
Exit Do
End If
OriginalDate = DateAdd("d", intAdd, OriginalDate)
Loop
AddWorkDays = dtmReturnDate
End Function
Hi

Much as I like endless loops(?), I think something like this should do what you have described.
Expand|Select|Wrap|Line Numbers
  1. Public Function AddWorkDays(OriginalDate As Date, DaysToAdd As Integer) As Date
  2. 'OriginalDate = First Day to calculate number of working days from
  3. 'DaysToAdd = Number of Working Days to add to OriginalDate
  4. 'Returns the date that is the last working day for the number of days
  5. 'To look back, pass a negative number of days
  6. 'If 0 is entered, the current date is returned
  7.  
  8. Dim i As Integer
  9.  
  10. AddWorkDays = OriginalDate
  11. For i = 1 To DaysToAdd Step Sgn(DaysToAdd)
  12.     If Weekday(OriginalDate + i, vbMonday) <= 5 Then 'It is a weekday
  13.         If IsNull(DLookup("[Date]", "Holidays", "[Date] = #" & Format(OriginalDate + i, "mm/dd/yy") & "#")) Then
  14.             AddWorkDays = OriginalDate + i
  15.         End If
  16.     End If
  17. Next i
  18. End Function
I would suggest using a yes/no data type for the 'Holiday' field. Also, please change the field name for 'Date' (this is a keyword/function) to something else, if you can, as this will probably give you problems at some time.

MTB
Jan 2 '08 #2
MikeTheBike
639 Recognized Expert Contributor
Hi

Much as I like endless loops(?), I think something like this should do what you have described.
Expand|Select|Wrap|Line Numbers
  1. Public Function AddWorkDays(OriginalDate As Date, DaysToAdd As Integer) As Date
  2. 'OriginalDate = First Day to calculate number of working days from
  3. 'DaysToAdd = Number of Working Days to add to OriginalDate
  4. 'Returns the date that is the last working day for the number of days
  5. 'To look back, pass a negative number of days
  6. 'If 0 is entered, the current date is returned
  7.  
  8. Dim i As Integer
  9.  
  10. AddWorkDays = OriginalDate
  11. For i = 1 To DaysToAdd Step Sgn(DaysToAdd)
  12.     If Weekday(OriginalDate + i, vbMonday) <= 5 Then 'It is a weekday
  13.         If IsNull(DLookup("[Date]", "Holidays", "[Date] = #" & Format(OriginalDate + i, "mm/dd/yy") & "#")) Then
  14.             AddWorkDays = OriginalDate + i
  15.         End If
  16.     End If
  17. Next i
  18. End Function
I would suggest using a yes/no data type for the 'Holiday' field. Also, please change the field name for 'Date' (this is a keyword/function) to something else, if you can, as this will probably give you problems at some time.

MTB
Hi
On overnight refection there is a logical hole in previous code (when OrigionalDate is not a valid workday and DaysToAdd =0), so two mods
Expand|Select|Wrap|Line Numbers
  1. Public Function AddWorkDays(OriginalDate As Date, DaysToAdd As Integer) As Date
  2. 'OriginalDate = First Day to calculate number of working days from
  3. 'DaysToAdd = Number of Working Days to add to OriginalDate
  4. 'Returns the date that is the last working day for the number of days
  5. 'To look back, pass a negative number of days
  6. 'If 0 is entered, the current date is returned
  7.  
  8. Dim i As Integer
  9.  
  10. AddWorkDays = OriginalDate
  11. If DaysToAdd = 0 Then Exit Function
  12. For i = 0 To DaysToAdd Step Sgn(DaysToAdd)
  13.     If Weekday(OriginalDate + i, vbMonday) <= 5 Then 'It is a weekday
  14.         If IsNull(DLookup("[Date]", "Holidays", "[Date] = #" & Format(OriginalDate + i, "mm/dd/yy") & "#")) Then
  15.             AddWorkDays = OriginalDate + i
  16.         End If
  17.     End If
  18. Next i
  19. End Function
Line 11 added and line 12 moded.

MTB
Jan 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1211
by: Jack | last post by:
Hi, I'm wondering if someone can help with the following problem. I have 2 tables in an access database from which I would like to create a third table. They look like this: table 1 table 2 ======== ========
7
8873
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
4
5334
by: Lee Chapman | last post by:
Hi, Can anyone tell me why in the code below, the call to ClearChildViewState() has no effect? To paraphrase the code: I'm using view state. I have a textbox and a submit button (and a label that can be ignored). When I press the button the first time, the click handler hides the textbox. Pressing the button a second time unhides the textbox. The text box is maintaining its value when hidden via view state. (The value is NOT being...
7
4264
by: | last post by:
Hello, I would like to do the following from a asp.net button click: <form method="POST" action="https://www.1234.com/trans_center/gateway/direct.cgi"> <input type="hidden" name="Merchant" value="Merchant Name"> <input type="hidden" name="OrderID" value="Unique OrderID value"> <input type="hidden" name="email" value="Customers email address (OPTIONAL)">
15
4645
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
2
2180
by: murdock | last post by:
Is there a way to perform functions upon databound data that is to be used in a GridView? For example, in the following code where I am using a GridView to display a resulting asp:SqlDataSource <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="402px" Width="612px" AllowSorting="True" PageSize="50">...
1
2879
by: dba123 | last post by:
I need to perform Asynchronous Inserts using DAAB. So far I have a method which does an insert but how can I do this Asyncronously so that it does not affect the load on our public production website? This question is wide open but make sure you give me some ideas in context with DAAB syntax. Some thoughts are threading, ATLAS, etc. but I have no clue how to even approach an Asynchronous Insert or any techniques at this point. Also, I...
1
4868
by: Simon | last post by:
Dear reader, Some times I receive an error message by using the functions: Left(;2) Mid(;5;2)
3
7494
by: victoria.rego | last post by:
Hi there, My application is generating a "The OpenForm action was cancelled" error and I can't seem to figure out why. The best part about it is that it's only one user in the entire building - it works perfectly fine for the rest of us. So troubleshooting is extremely difficult. Here is the code involved. The command button that opens the form, the code in the form, and the code in the subform of the form.
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
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
10443
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
10216
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9044
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...
0
5437
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...
1
4113
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
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.