Access VBA for command button - vba

when I debug in the editor I don't get syntax errors, but when I click the button on my form nothing happens. Trying to add 6 months to the field with a click of the button. Does anyone know if this code is wrong or incomplete?
Private Sub Ctl6mosBtn_Click()
EXPIRATIONDATE = [AUTO POLICIES.EFFECTIVE DATE] = DateAdd("m", 6, EXPIRATIONDATE)
End Sub
Thanks for you any insight
Frank
I have two fields on my form
1-AUTO POLICIES.EFFECTIVE DATE which is the effective date of a policy.
2-EXPIRATIONDATE which is the expiration date of the policy.
I have a button labeled 6 Mos which when clicked should fill the EXPIRATIONDATE 6 months after the Effective Date. Nothing happens, no errors, fields doesn't fill!

Related

ListBox VBA Userform

Hi am trying to make a booking form for a dog agility field with a date and time slots have near enough done it the only issue i have is double booking so i would like to within the book cmd button to check the monthview1 in the data sheet and to check if the time is available on the chosen date.
any help would be massively appreciated, hope this make sense below is the code i have which the booking form work fine with.
in a ideal world i would like the listbox to show available rooms on the dates selected. but this is what i have atm. this is with in the listboxclick vba code
If MonthView1 = Sheets("Camping Bookings")("G:G") Then esleif MonthView2 = Sheets("Camping Bookings")("H:H") Then esleif ListBox1 = Sheets("Camping Bookings")("F:F")then MsgBox "booking is not available" exit sub end if

Going through day, month and year on VBA DTPicker using TAB

On my userform with a calendar users can quickly navigate through all inputfields with the TAB order. That also works for the DTPicker insofar that the focus is set on the DTPicker first element = Day (I have format dd/MM/yyyy). However, after entering the day and pressing TAB the focus is on the next TextBox instead of the Month of the DTPicker.
Is there a way to use keyboard to set focus on MM after entering dd and on yyyy after entering MM? Or that after entering the day the cursos automatically moves to month and then to year?
Thanks a lot!

How to add specific number in last row from UserForm using VBA?

I am the beginner of VBA and need some help from you in code.
My problem is that I want to make some kind of UserForm using VBA in Excel to generate new numbers for new ticket.
The UserForm will be needed to manage tickets about received problems.
The case is that I want to make new number of ticket by clicking button "New Ticket". After that, in UserForm, the "Ticket Number" field will be blocked and show assigned new ticket number, "Date Opened" field will show current date automatically and "Accept" button will change text to "Create" button and will be enabled. After clicking "Create" button, UserForm will close and write line about ticket with details in last row in Excel sheet.
I also want to have ticket number starting with specific number e.g. 60555, 60556, 60557 etc. The problem is that now I am receiving numbers 1, 2, 3 etc.
Below you can see some screenshots of problem and part of created code.
UserForm "Manage Tickets"
After "Create" button, what is showing in last row in Excel Sheet
What I want to show in last row in Excel Sheet after "Create" button
If there is a way also to show text "[BHD#?????]" in UserForm and add it by UserForm, it will be very helpful for me!
Part of code which is responsible for "New Ticket" button:
Private Sub btwNewTicket_Click()
ClearFields
LastRow = ThisWorkbook.Sheets("Issue Log").Cells(Rows.Count, 2).End(xlUp).End(xlUp).Row - 4
Me.tbTicketNo.Value = LastRow
Me.tbTicketNo.Locked = True
Me.tbDateOpen = Date
Me.btnAccept.Caption = "Create"
Me.btnAccept.Enabled = True
End Sub
Thanks in advance!
You can concatenate strings with the & symbol. Hence a possible solution for your needs would be:
Me.tbTicketNo.Value = "[BHD#" & Format(LastRow,"00000") &"]"
The Format(LastRow, "00000") makes the value always five digits long. With LastRow=1 the output would be [BHD#00001].
If you want to start by a value of 60555 than just add this value
Me.tbTicketNo.Value = "[BHD#" & 60555+LastRow &"]"
With LastRow=1 the output would be [BHD#60556]

How to replace label with dates

I am using Visual Basic 2010. My question can best explained by these images.
I would like to know how to make the labels appear as dates depending on what the DateTimePicker is set on. For Example:
This is what the code looks now that I have solved my issue.
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
Me.Label14.Text = CStr(Me.MonthCalendar1.SelectionRange.Start)
Me.Label13.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(6))
Me.Label12.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(1))
Me.Label11.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(2))
Me.Label10.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(3))
Me.Label9.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(4))
Me.Label15.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(5))
End Sub
I don't have Visual Studio installed on this computer, so I can't give you the exact code, so I will try to explain it.
In the code of the event for the DateTimePicker, you have to calculate for each label the difference in days of the week from your date to the date you want to show (Wednesday to Saturday - 3 days (and you have a little error in the images - you have to switch Wednesday with Tuesday), Thursday to Saturday - 2 days, and so on...).
After that, you subtract (or add, if the day is after the chosen date) the referential date with the corresponding value from above, and you get the date needed. Now you only have to show the result in the label.
Found the answer to my own question.
To retrieve a date and display it in a label:
In the File menu, click New Project.
The New Project dialog box appears.
Click Windows Forms Application and then click OK.
Add a Label control to the form, leaving the default name Label1.
Remove the text from the Text property of the Label control.
Add a MonthCalendar control to the form, leaving the default name MonthCalendar1.
Double-click the MonthCalendar control to enter the default event handler in the Code Editor.
In the MonthCalendar1_DateChanged event handler, add the following code to add items to the list:
Me.Label1.Text = CStr(Me.MonthCalendar1.SelectionRange.Start)
Return to Designer view and add a DateTimePicker control to the form, leaving the default name DateTimePicker1.
Double-click the DateTimePicker control to enter the default event handler in the Code Editor.
In the DateTimePicker_ValueChanged event handler, add the following code to add items to the list:
Me.Label1.Text = CStr(Me.DateTimePicker1.Value)
Press F5 to run the program.
When the form appears, click a date in the MonthCalendar control and verify that the date is displayed in the label.
Click the drop-down arrow of the DateTimePicker control and select a date.
The date and time are displayed in the label.

Windows Phone DatePicker doesn't update its Value

I make a windows phone 7.8 app and i'm using a datepicker.
When i load the page that contains the datepicker, i pass the date and is displayed correctly.My code is:
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
Dim mydate As String = Nothing
If NavigationContext.QueryString.TryGetValue("date", mydate) Then
eventdate = Date.Parse(mydate)
datePicker.Value = eventdate
EndIf
End Sub
But when i try to change the date , the datepicker doesn't hold the new date. Does anybody know why?
Your problem is due to the way you're not correctly managing the page lifecycle.
When you go to the date selector this is actually a separate page. When tapping the "tick" to confirm the new data selection you'll return to your page. Based on your code above, at this point you'll load the date from the NavigationContext again and so the selected date is lost.
The solution is to query the NavigationEventArgs and only read the query string when the NavigationMode is New.