I got this code below which populates the Standard (Base) calendar with public holidays. Can anyone point my in the right direct to do the same onto a resource calendar.
Example resource calendar name = "Joe Bloggs"
here is the code I've got working for the base calendar.
Sub Create_New_Exceptions()
Dim e As Exception
Dim cal As Calendar
Dim CalName As String
CalName = ActiveProject.Calendar.Name
ActiveProject.BaseCalendars(CalName).Exceptions.Add Type:=1, Start:="1/01/2020", Finish:="1/01/2020", Name:="New 's Day"
'copy above to insert more public holidays
End Sub
Any help will be appreciated.
Use the Calendar property of the Resource to add calendar exceptions:
ActiveProject.Resources("Joe Bloggs").Calendar.Exceptions.Add Type:=1, Start:="1/01/2020", Finish:="1/01/2020", Name:="New 's Day"
Related
I am working on a library management project.
I have almost the complete project but I am facing a problem, when I issue a book to someone, I have to put a date of issue and a date of limit to return the book.
But on the date of the return book I want it to set automatically 2 months after the date of issue.
I do not have any code, all I have is 2 datetimepicker one for the issue and one for the return.
Can someone help me with this?
Thank you in advance.
EDIT:
Code that I have tried till now:
Private Sub DateTimePicker2_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker2.ValueChanged
DateTimePicker2.Value = DateTimePicker1.Value.AddMonths(+2).ToString("dd/MM/yyyy")
End Sub
It's that simple:
Private Sub AddTwoMonth()
DateTimePicker1.Value = Today
DateTimePicker2.Value = DateTimePicker1.Value.AddMonths(2)
End Sub
Have fun.
I live in Australia and we use the d/mm/yyyy date format. I am trying to make a userform with VBA in excel that will read the a cell (A1), display it in a textbox. The user can then enter a date in another textbox and set that date back to cell(A1). The problem I have is that when I am reading the date from Cell(A1) is changes from d/mm/yyyy to m/dd/yyyy in the textbox. I have used the
" = Format(DateCurrent_Tbx.Value, "d/mmm/yy")" but it makes no difference. I am using Excel 2010 32bit, on a Windows 7 SP1 64Bit Computer, and have the computer set to English (Australian) time format. Cell(A1) is set to custom formatting "d/mm/yyyy"
As the VBA code for the file I'm using is very long, I've replicated the error in a smaller userform (attached excel file).
Sample of Excel file with Error
Private Sub LockInput_Cmd_Click()
SetDate_Cmd.Caption = InputDate_Tbx.Value
SetDate_Cmd.Caption = Format(SetDate_Cmd.Caption, "d/mmm/yy")
End Sub
Private Sub SetDate_Cmd_Click()
ThisWorkbook.Sheets(1).Range("A1").Value = SetDate_Cmd.Caption
DateCurrent_Tbx.Value = ThisWorkbook.Sheets(1).Range("A1").Value
DateCurrent_Tbx.Value = Format(DateCurrent_Tbx.Value, "d/mmm/yy")
End Sub
Private Sub UserForm_Initialize()
DateCurrent_Tbx.Value = ThisWorkbook.Sheets(1).Range("A1").Value
DateCurrent_Tbx.Value = Format(DateCurrent_Tbx.Value, "d/mmm/yy")
End Sub
I have been racking my head and searching the web for days to no avail. I hope I have explained things clearly enough.
There is some confusion with strings that look like dates and actual dates and the EN-US-centric VBA default MDY locale is doing nothing to alleviate that.
First off, the date in A1 is a number between 0 and 42,225 (Aug 9, 2015 is 42,225); nothing more or less. You can dress it up as d/mm/yyyy regardless of what locale your computer system is running under. Mine runs under EN-US and I have no trouble displaying a date as 9/08/2015 if I use a number format mask of d/mm/yyyy. To get the displayed date from A1 back into the textbox AS A STRING use the Range.Text property. This is the displayed text that is in a cell. It is read-only so you cannot stuff a "9/08/2015" string back into it.
Private Sub UserForm_Initialize()
DateCurrent_Tbx.Value = ThisWorkbook.Sheets(1).Range("A1").TEXT
End Sub
As far as user input of a 'string-that-looks-like-a-date' is concerned, you may have to trust your users a bit to do the right thing. If they can be relied upon to input in a DMY format, you can split the pieces and put them together properly using the DateSerial function.
Private Sub LockInput_Cmd_Click()
dim dt as date, vDT as variant
vDT = split(InputDate_Tbx.Value, chr(47)) 'split the string-date on the forward slash
dt = DateSerial(vDT(2), vDT(1), vDT(0)) 'create a real date
SetDate_Cmd.Caption = Format(dt, "d/mmm/yy") 'use any format mask you want to create another string-date
End Sub
Private Sub SetDate_Cmd_Click()
dim dt as date, vDT as variant
vDT = split(SetDate_Cmd.Caption, chr(47)) 'split the string-date on the forward slash
dt = DateSerial(vDT(2), vDT(1), vDT(0)) 'create a real date
ThisWorkbook.Sheets(1).Range("A1").Value = dt 'put the actual date back into A1
End Sub
As far as the CDate function is concerned, I would avoid its use. If you stuff "19/08/2015" into CDate (try it in the VBE's Immediate window as ?CDate("19/08/2015")) it will correctly interpret it as 19-Aug-2015 but that is only because IT HAS NO OTHER CHOICE! If you try the same with ?CDate("9/08/2015") you end up with 08-Sep-2015 because whenever there is a choice, CDate opts for the EN-US locale of MDY. Best not to rely on this one. I believe the DateValue function is at least as unreliable.
I am currently building a string and require a date to be filtered.
Example :
sb.Append("&NextPayDate=" & app.IncomeNext.ToString("yyyy-MM-dd"))
this collects a date from a form they fill in and then it gets posted out.
The problem is the area that recieves this post does not allow weekends, so the date cannot be on a weekend.
This is how i filter a telephone number and it works great
If app.LandPhone.Length = 10 Or app.WorkPhone.Length = 10 Then
sb.Append("Only 11-digit phones supported;")
How do i filter the date so it wont accept weekend dates.
Thanks
Firstly you need to get/set the type of calendar you use importing:
Imports System.Globalization
Then check if app.IncomeNext includes that information already or use this:
Dim myCal As Calendar = CultureInfo.InvariantCulture.Calendar
If (myCal.GetDayOfWeek(app.IncomeNext).equals("Saturday") or myCal.GetDayOfWeek(app.IncomeNext).equals("Sunday"))
Then
sb.Append("No weekends supported;")
End If
According the configuration of app.IncomeNext you'll probably need to insert the type of calendar.
Thanks Novemberland, that worked great , just forget the End IF
Here is the full solution.
Imports System.Globalization
Friend Overrides Function Filter() As String
Dim sb As New StringBuilder()
If (myCal.GetDayOfWeek(app.IncomeNext).equals("Saturday") or myCal.GetDayOfWeek(app.IncomeNext).equals("Sunday"))
Then
sb.Append("No weekends supported;")
End If
Return sb.ToString()
End Function
If app.IncomeNext.DayOfWeek = DayOfWeek.Saturday Or
app.IncomeNext.DayOfWeek = DayOfWeek.Sunday Then
I am trying to write some VBA in Microsof Access (if VBA is the way to go?). What I need is a pop up message alerting someone that a deployment is happening within the next week.
My table is called Tasks_List and there is a field called Deployment_Date.
What I think I need is to put together an OnLoad for the initial form. It would check today's date and check through Deployoment_Date and show a pop up if any deployments are happening within the next week. The pop up should show what deployments are happening e.g. Initiating_System, Deployment_Date and Description.
Thank you in advance, I've hit a brick wall on this. I'll post what I've tried but I have no VBA knowledge and it is pretty bad.
What I tried:
Private Sub Report_Open(Cancel As Integer)
Dim varX As Variant
varX = DLookup(Tasks_List.[Deployment_Date]< Now - 20)
If varX > 0 Then GoTo line2
line1: msgbox "Deployment approacing for: "
line2:
End Sub
EDIT: After help below I have created a query and form for this. Using Dcount:
Private Sub Detail_OnLoad()
Deploy = DCount("*", "Tasks_List_Popup_Query")
If Deploy <> 0 Then
DoCmd.OpenForm "Tasks_List_Popup_Query_Form"
DoCmd.GoToRecord , , acNewRec
End If
End Sub
You should not need any VBA. Create a query that selects the relevant records and create a form based on the query. You can use DCount to ensure that there are records before you launch the form, which would take a little VBA.
SELECT * FROM Tasks_List WHERE [Deployment_Date]< (Date - 20)
For the DCount:
Deploy = DCount("*","TheQuery")
Is there anyway i can select multiple dates in a Date Time Picker in Vb.net?
Use BoldedDates Property in your month calendar to get the array of DateTime objects. You can use this to get your collection and finally clear the bold dates after storing it, so that it can be reused.
Selecting Multiple dates in a DateTimePicker in vb.net?
If you want to select a range of dates using a DateTimePicker, then the best way if probably two DateTimePicker controls a from date and a to date.
You can then change the date of the opposite control when the first date is picked to make sure the FromDate is before the ToDate and vice versa
I found MonthCalendar control which seems to be perfect for this purpose but i cant find the option (method, property) to get the selectedDates and then use them.
If you want to use a MonthCalendar control you can specify a MaximumSelectionCount property and then the user can select dates by clicking on one and shift-clicking on another date
You can retrieve the dates the user selected by using the SelectionRange, or SelectionStart and SelectionEnd properties
How about if i want to select random dates, like 4th, 6th, 10th Feb.
This is more complex. A suggestion - you could use the BoldedDates array of the MonthCalendar and when a user clicks on a day, you bold it. You can then read the array after they have finished their selection? Maybe someone else has a suggestion for this?
Private listDates As List(Of DateTime)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Suppose that you have the following list of dates below
listDates = New List(Of DateTime)()
listDates.Add(DateTime.Now)
listDates.Add("12/22/2012")
listDates.Add(DateTime.Now.AddDays(-10))
End Sub
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Handles Calendar1.DayRender
'Set Default properties
e.Day.IsSelectable = False
e.Cell.BackColor = System.Drawing.Color.Gray
'Now loop through the list of dates and make it
'Selectable
For Each d As DateTime In listDates
Calendar1.SelectedDates.Add(d)
If e.Day.IsSelected Then
e.Cell.BackColor = System.Drawing.Color.Green
e.Day.IsSelectable = True
End If
Next
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged
'Print the selected date
Response.Write("You have selected: " & Calendar1.SelectedDate.ToShortDateString())
End Sub
i found it, and try. it work,
original source from here
There is no way to do this inside the existing DateTimePicker control.
The best alternative solution will depend on your specific situation. What's the context? If you're expecting the user to pick dates which are close together (and the range isn't too big) a reasonably simple solution is to use another control which will allow multiselect on a list.
For example a CheckedListBox or DataGridView.
Then populate it with a list of dates. In effect offering the user a picklist of dates.