Dates Switching from Form to Cell

scotball

Active Member
Joined
Oct 23, 2008
Messages
375
I have a form with 2 date fields which have some formatting options in the VBA code.

When I put in a date like 10/08/2018 in the form... when it puts the date in to the corresponding cell on submission, it's switching the date to 08/10/2018.

I've formatted the cells to dd/mm/yyyy and the code in the VBA is:

Code:
Private Sub CommandButton1_Click()    With DOBTextBox
        .Value = dDate
        .NumberFormat = "dd/mm/yyyy"
    End With
End Sub




Private Sub DOBTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.DOBTextBox
        If Len(.Text) > 0 Then
            If Not .Text Like "##/##/####" Then
                MsgBox "Invalid DOB date format" & Chr(10) & "Please re-enter as dd/mm/yyyy", vbCritical, "Invalid Format"
                Cancel = True
            Else
                dDate = DateValue(.Text)
            End If
        End If
    End With
End Sub


Private Sub CommandButton2_Click()
    With SessionsBox
        .Value = dDate2
        .NumberFormat = "dd/mm/yyyy"
    End With
End Sub




Private Sub SessionsBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.SessionsBox
        If Len(.Text) > 0 Then
            If Not .Text Like "##/##/####" Then
                MsgBox "Invalid Session date format" & Chr(10) & "Please re-enter as dd/mm/yyyy", vbCritical, "Invalid Format"
                Cancel = True
            Else
                dDate2 = DateValue(.Text)
            End If
        End If
    End With
End Sub

Any ideas on how to stop the numbers from switching please?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top