In my Form, I created a button that opens another form called 'CalenderForm' This is a…
- User
In my Form, I created a button that opens another form called 'CalenderForm' This is a Calender Form I got from the web that I have imported into my project. I am not sure If I needed to create the button to open the CalenderForm so I have included the instructions supplied with the Calender form below. Further below, I have also included my current Form Code. Can you, tell me what to do and if possible adjust my current code to use the new CalendarForm.
Using the date picker Once the CalendarForm date picker has been imported into your workbook, it can be used by calling the CalendarForm.GetDate function. The GetDate function is the single point of entry into the date picker. It controls everything. Every argument in the function is optional, meaning your function call an be as simple as dateVariable = CalendarForm.GetDate. That's all there is to it. The date picker initializes and pops up, the user selects a date, and the selection is returned to your variable. Dim dateVariable as Date dateVariable = CalendarForm.GetDate From there, you can use as many or as few arguments as you want in order to get the desired calendar that suits your needs. Below are some examples of different calendars you can get from the various arguments in the GetDate function. All default values are also set in the GetDate function, so if you want to change default colors or behavior without having to explicitly do so in every function call, you can set those values in the argument list for the function. By setting the various arguments, you can obtain vastly different calendars, all with the same function.
Option Explicit
Private Sub CommandButton1_Click() Application.EnableEvents = False ' Get data from form Dim TaskDescription As String: TaskDescription = Me.TaskDescription.value Dim TaskType As Long: TaskType = Me.TaskType.ListIndex + 1 ' Adjust for 0-based indexing Dim DateCreated As Date: DateCreated = Me.DateCreated.value Dim Collaborators As Long: Collaborators = Me.Collaborators.ListIndex + 1 ' Adjust for 0-based indexing Dim Resources As Long: Resources = Me.Resources.ListIndex + 1 ' Adjust for 0-based indexing Dim TaskPriority As Long: TaskPriority = Me.TaskPriority.ListIndex + 1 ' Adjust for 0-based indexing Dim CompletionDate As Date: CompletionDate = Me.CompletionDate.value Dim StagesRequired As Long: StagesRequired = Me.StagesRequired.ListIndex + 1 ' Adjust for 0-based indexing
' Calculate difference in days Dim diffDays As Long: diffDays = DateDiff("d", Date, CompletionDate)
' Determine target sheet based on difference in days Dim targetSheet As String Select Case diffDays Case Is <= 3: targetSheet = "Day" Case 4 To 9: targetSheet = "Week" Case 10 To 20: targetSheet = "Forthnight" Case 21 To 59: targetSheet = "Month" Case 60 To 89: targetSheet = "QtrYear" Case 90 To 209: targetSheet = "HalfYear" Case Else: targetSheet = "Year" End Select ' Find next available row Dim lastRow As Long: lastRow = Sheets(targetSheet).Cells(Rows.Count, 1).End(xlUp).Row + 1 'Application.Wait (Now + TimeValue("0:00:01")) ' Write data to sheet With Sheets(targetSheet) Sheets(targetSheet).Unprotect Password:="edit" ' Unlock the sheet .Cells(lastRow, 1).value = TaskDescription .Cells(lastRow, 2).value = Me.TaskType.value .Cells(lastRow, 3).value = DateCreated .Cells(lastRow, 4).value = Me.Collaborators.value .Cells(lastRow, 5).value = Me.Resources.value .Cells(lastRow, 6).value = Me.TaskPriority.value .Cells(lastRow, 7).value = CompletionDate .Cells(lastRow, 8).value = Me.StagesRequired.value Sheets(targetSheet).Protect Password:="edit" ' Unlock the sheet End With 'Application.Wait (Now + TimeValue("0:00:01")) ' Display confirmation message MsgBox "Your new task has been recorded in " & targetSheet & ".", vbInformation
- Assistant
- User
In my previous code, I had a text field where I manually enetered my CompletionDate. Do I still need to keep the text field in the Form with the inclusion of this CalendarForm, or should I delete the text field
- Assistant
With the inclusion of the CalendarForm for selecting the CompletionDate, you no longer need the text field for manually entering the date. You can remove the text field from your form as the CalendarForm will handle the selection of the date.
Therefore, you should delete the text field for the CompletionDate from your form. Update your form design to remove the manual entry field for CompletionDate. The CalendarForm will provide a user-friendly way to choose and input the completion date.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.