Formatting a Date field into a form?????

K

K1KKKA

I just know this is going to be easy.

using the code below to place 2 dates into specific cells on a sheet
the generates my autofilter to run a query between these dates, this
bit works fine, apart from the date entry, i would like the date to
show as "dd mm yy" but when i enter it into the form it appears as "mm
dd yy" i know that it will be a case of adding the 'Format' to the
code within the form but am having trouble exactly where to place it.

Any help please

Steve



Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")

iRow = ws.Cells(Rows.Count, 18) _
.End(xlUp).Offset(17, 0).Row

ws.Cells(iRow, 10).Value = Me.date1.Value
ws.Cells(iRow, 11).Value = Me.date2.Value

Me.date1.Value = ""
Me.date2.Value = ""
Me.date1.SetFocus

End Sub
 
D

Dave Peterson

Are you populating the textbox when the form opens?

If yes, then use the UserForm_Initialize procedure.


Private Sub UserForm_Initialize()

me.date1.value = format(somedatefromsomewhere, "dd mm yy")
me.date2.value = format(somedatefromsomewhereelse, "dd mm yy")

End Sub
 
K

K1KKKA

Are you populating the textbox when the form opens?

If yes, then use the UserForm_Initialize procedure.

Private Sub UserForm_Initialize()

me.date1.value = format(somedatefromsomewhere, "dd mm yy")
me.date2.value = format(somedatefromsomewhereelse, "dd mm yy")

End Sub












--

Dave Peterson- Hide quoted text -

- Show quoted text -

Thanks Dave,

Have not populated the date fields, as i was hoping to have these as
entered dates that then populate the cells specified, was just hoping
to use the format command to set the textboxes to the following "dd/mm/
yy"



Steve
 
D

Dave Peterson

Maybe after the user changes the textbox and is leaving:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsDate(Me.TextBox1.Value) Then
Me.TextBox1.Value = Format(Me.TextBox1.Value, "dd/mm/yy")
Else
Beep
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top