I need to create a database that will be used to schedule patches. Many of our patches happen on the 1st Saturday of the month, but some happen on the 2nd Thursday after the 1st Tuesday every month.
Ive been attempting to use the DATEPART and WEEKDAY functions but without success. Figuring out the 1st Saturday shouldnt be to hard, even if I havent managed to figure that out just yet, but the other is beyond my experience.
4 5160
I need to create a database that will be used to schedule patches. Many of our patches happen on the 1st Saturday of the month, but some happen on the 2nd Thursday after the 1st Tuesday every month.
Ive been attempting to use the DATEPART and WEEKDAY functions but without success. Figuring out the 1st Saturday shouldnt be to hard, even if I havent managed to figure that out just yet, but the other is beyond my experience.
Here's your answer: -
-
Function FirstSatOfMonth() As Date
-
-
For x = 0 To 6
-
If Weekday(DateSerial(Year(Date), Month(Date), 1) + x, vbUseSystemDayOfWeek) = vbSaturday Then
-
FirstSatOfMonth = DateSerial(Year(Date), Month(Date), 1) + x
-
End If
-
Next x
-
End Function
-
-
Function SecondThursdayafterFirstTuesday() As Date
-
For x = 0 To 6
-
If Weekday(DateSerial(Year(Date), Month(Date), 1) + x, vbUseSystemDayOfWeek) = vbTuesday Then
-
SecondThursdayafterFirstTuesday = DateSerial(Year(Date), Month(Date), 1) + x + 9
-
End If
-
Next x
-
End Function
-
-
Wow! Thanks for the quick response. Its midnight here, didnt think anyone would reply until tomorrow morning. You rock!
I used the information you gave me to create 33 functions. They all work perfect now, but Ive run into another problem.
The following is a quick example of what I am trying to do:
---
Private Sub MonthCombo_AfterUpdate(Cancel As Integer)
[test] = First_Saturday()
End Sub
---
Basically when the user changes the month in the form header it will update all the patch windows using their particular function.
First_Saturday() is in a module named DateCalculation.
Originally I had attached each function directly to related textbox as default value which worked just fine until I figured it need the flexibility of changing the month value.
I had changed a function to replace Month(Date) with [Form]![test]![MonthCombo] which works, but only as the form loads. I need the data to update if the month is changed.
This is the following error I get as the AfterUpdate runs...
The expression After Update you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.
I used the information you gave me to create 33 functions. They all work perfect now, but Ive run into another problem.
The following is a quick example of what I am trying to do:
---
Private Sub MonthCombo_AfterUpdate(Cancel As Integer)
[test] = First_Saturday()
End Sub
---
Basically when the user changes the month in the form header it will update all the patch windows using their particular function.
First_Saturday() is in a module named DateCalculation.
Originally I had attached each function directly to related textbox as default value which worked just fine until I figured it need the flexibility of changing the month value.
I had changed a function to replace Month(Date) with [Form]![test]![MonthCombo] which works, but only as the form loads. I need the data to update if the month is changed.
This is the following error I get as the AfterUpdate runs...
The expression After Update you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.
The sub routine that you sent, I'm assuming the [Test] is a control on the current form this sub is in?
If so, simply do the following: -
-
Private Sub MonthCombo_BeforeUpdate(Cancel As Integer)
-
-
me.Test = First_Saturday()
-
-
End Sub
-
Hope that helps,
Joe P.
p.s. The AfterUpdate Event doesn't support (Cancel as Integer). That's why you were getting the error.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paolo |
last post by:
I have a form on which I have a field named DOB which stores the
client's date of birth (mm/dd/yyyy).
I would like that when users open the form, a message should alert if
that person is over...
|
by: Mark Hall |
last post by:
Our reporting cycle goes from Wednesday to Wednesday an I need to
calculate the next Wednesday after the update was received.
If an upate comes in on say a Tuesday (eg 20 Jan 04) then I want a...
|
by: Paul Mendez |
last post by:
Performance_Date SumOfBudget_NOI CurrYTD_BudgetNOI_Total
1/1/2004 $4,184,626.00 ?
2/1/2004 $4,484,710.00 ?
3/1/2004 $4,537,424.00 ?
4/1/2004 ...
|
by: Gustavo G. Rondina |
last post by:
It is possible to caclulate every year's easter using simple
mathematical operations. Here is a code that does the trick:
http://www.brlivre.org/c/easter.c
I found the math scheme in an...
|
by: Jason |
last post by:
I've created a service in c# that performs a certain action at a particular
day of the month
I want this service to kick off the action every third Tuesday of the month.
How would I set the...
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
HI I have a stored procedure that returns data with a date field in the form
of a DateTime type. I need to place data in variables based on days of the
week starting with the first thursday of the...
|
by: cbalian |
last post by:
I am looking for a TSQL code that would calculate a specific date each month that varies based on the following condition:
I need the result that would return the date of the Thursday after the...
|
by: ncsthbell |
last post by:
I am having problems getting the end date to calculate correctly.
I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
|
by: =?Utf-8?B?QWw=?= |
last post by:
I am working in vb2005. how can I calculate business days (not including
holidays and weekends) between 2 dates? thanks
Al
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
| |