leopardhawk
Well-known Member
- Joined
- May 31, 2007
- Messages
- 611
- Office Version
- 2016
- Platform
- Windows
The following code works perfectly for me but I would like to improve it by making it so that if I select an ARRIVAL DATE in the future, say in the year 2017, that the default DEPARTURE DATE would then be at least that far in the future. I hope this makes sense and that there is a way to do it. Appreciate any and all replies.
Code:
Private Sub CancelCommandButton_Click()
Unload Me
End Sub
Private Sub ClearCommandButton_Click()
Call UserForm_Initialize
End Sub
Private Sub Label21_Click()
End Sub
Private Sub OKCommandButton_Click()
Dim emptyRow As Long
'Make Sheet4 Active
Sheets(4).Activate
'Determine EmptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Export Data to worksheet
Cells(emptyRow, 1).Value = NameTextBox.Value
Cells(emptyRow, 2).Value = ArrivalDTPicker.Value
Cells(emptyRow, 3).Value = DepartureDTPicker.Value
Cells(emptyRow, 4).Value = BookingDTPicker.Value
Cells(emptyRow, 5).Value = AdultsComboBox.Value
Cells(emptyRow, 6).Value = ChildrenComboBox.Value
Cells(emptyRow, 7).Value = DepositTextBox.Value
Cells(emptyRow, 8).Value = OrderNumberTextBox.Value
Cells(emptyRow, 9).Value = CreditCardComboBox.Value
Cells(emptyRow, 10).Value = CardNumberTextBox.Value
Cells(emptyRow, 11).Value = UCase(CardNameTextBox.Value) 'Put card name in upper case on worksheet
Cells(emptyRow, 12).Value = MonthComboBox.Value
Cells(emptyRow, 13).Value = YearComboBox.Value
Cells(emptyRow, 14).Value = SecurityTextBox.Value
Cells(emptyRow, 15).Value = PhoneTextBox.Value
Cells(emptyRow, 16).Value = AddressTextBox.Value
Cells(emptyRow, 17).Value = CityTextBox.Value
Cells(emptyRow, 18).Value = UCase(StateTextBox.Value) 'Put state name in upper case on worksheet
Cells(emptyRow, 19).Value = UCase(PostalTextBox.Value) 'Put postal name in upper case on worksheet
Cells(emptyRow, 20).Value = CountryComboBox.Value
Cells(emptyRow, 21).Value = EmailTextBox.Value
Cells(emptyRow, 22).Value = WebsiteComboBox.Value
End Sub
Private Sub UserForm_Initialize()
'Empty NameTextBox
NameTextBox.Value = ""
'Empty AddressTextBox
AddressTextBox.Value = ""
'Empty CityTextBox
CityTextBox.Value = ""
'Empty StateTextBox
StateTextBox.Value = ""
'Empty PostalTextBox
PostalTextBox.Value = ""
'Empty CountryComboBox
CountryComboBox.Value = ""
'Fill CountryComboBox
With CountryComboBox
.AddItem "US"
.AddItem "CA"
.AddItem "EU"
.AddItem "SA"
.AddItem "AU"
.AddItem "AF"
.AddItem "AS"
End With
'Empty PhoneTextBox
PhoneTextBox.Value = ""
'Empty EmailTextBox
EmailTextBox.Value = ""
'Default Date to Todays Date
ArrivalDTPicker.Value = Date
DepartureDTPicker.Value = Date
BookingDTPicker.Value = Date
'Empty AdultsComboBox
AdultsComboBox.Value = ""
'Fill AdultsComboBox
With AdultsComboBox
.AddItem "1"
.AddItem "2"
.AddItem "3"
.AddItem "4"
.AddItem "5"
.AddItem "6"
End With
'Empty ChildrenComboBox
ChildrenComboBox.Value = ""
'Fill ChildrenComboBox
With ChildrenComboBox
.AddItem "0"
.AddItem "1"
.AddItem "2"
.AddItem "3"
.AddItem "4"
.AddItem "5"
End With
'Empty CreditCardComboBox
CreditCardComboBox.Clear
'Fill CreditCardComboBox
With CreditCardComboBox
.AddItem "Visa"
.AddItem "MasterCard"
.AddItem "Discover"
End With
'Empty CardNumberTextBox
CardNumberTextBox.Value = ""
'Empty CardNameTextBox
CardNameTextBox.Value = ""
' Me is optional
Range("A1").Value = UCase(Me.CardNameTextBox.Text)
'Empty SecurityTextBox
SecurityTextBox.Value = ""
'Empty MonthComboBox
MonthComboBox.Clear
'Fill MonthComboBox
With MonthComboBox
.AddItem "01"
.AddItem "02"
.AddItem "03"
.AddItem "04"
.AddItem "05"
.AddItem "06"
.AddItem "07"
.AddItem "08"
.AddItem "09"
.AddItem "10"
.AddItem "11"
.AddItem "12"
End With
'Empty YearComboBox
YearComboBox.Clear
'Fill YearComboBox
With YearComboBox
.AddItem "15"
.AddItem "16"
.AddItem "17"
.AddItem "18"
.AddItem "19"
.AddItem "20"
.AddItem "21"
.AddItem "22"
End With
'Empty DepositTextBox
DepositTextBox.Value = ""
Me.DepositTextBox.Value = "$"
DepositTextBox.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
'Empty OrderNumberTextBox
OrderNumberTextBox.Value = ""
'Empty WebsiteComboBox
WebsiteComboBox.Clear
'Fill WebsiteComboBox
With WebsiteComboBox
.AddItem "airbnb"
.AddItem "flipkey"
.AddItem "homeaway"
.AddItem "housetrip"
.AddItem "trip advisor"
.AddItem "vacation rentals"
.AddItem "vrbo"
End With
'Set Focus on NameTextBox
NameTextBox.SetFocus
End Sub
Private Sub DepositTextBox_AfterUpdate()
If IsNumeric(DepositTextBox.Value) Then
'Format as currency
DepositTextBox.Value = Format(DepositTextBox.Value, "$#,##0.00")
Else
DepositTextBox.Value = "$"
End If
End Sub