ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Date format problem on form (https://www.excelbanter.com/excel-programming/395384-date-format-problem-form.html)

Ixtreme

Date format problem on form
 
I have a form on which a date can be entered in textbox1. After
clicking OK and submitting the form, the data is copied automatically
to a sheet.

The problem is that if a user wants to enter a date like 1 february
2007, the date in my sheet displays this date as if the user entered
2nd of january. What I would like to have is:

1. Preformat the textbox1 like DD/MM/YYYY. (If the form opens,
textbox1 should display DD/MM/YYYY. Upon selecting the cell, the user
can overwrite this with in this case: 01/02/2007
2. Display a label on the form displaying the long date of the date
the user has entered.
3. Display the correct date on my sheet as an integer (I use this
value to sort my list on)

PS: Everything independent of the users' local settings !!

Thanks,

Mark


Bob Phillips

Date format problem on form
 

"Ixtreme" wrote in message
oups.com...
I have a form on which a date can be entered in textbox1. After
clicking OK and submitting the form, the data is copied automatically
to a sheet.

The problem is that if a user wants to enter a date like 1 february
2007, the date in my sheet displays this date as if the user entered
2nd of january. What I would like to have is:

1. Preformat the textbox1 like DD/MM/YYYY. (If the form opens,
textbox1 should display DD/MM/YYYY. Upon selecting the cell, the user
can overwrite this with in this case: 01/02/2007



When loading the textbox, use

TextBox1.Text = Format(Range("A1").Value, "dd/mm/yyyy")


2. Display a label on the form displaying the long date of the date
the user has entered.
3. Display the correct date on my sheet as an integer (I use this
value to sort my list on)



Range("B2").Value = CLng(TextBox1.Text)



Ixtreme

Date format problem on form
 
Bob,

I receive a type mismatch. Is there something I have overseen here?

Private Sub CommandButton1_Click()

.......
Range("D" & LastRow).Value = CLng(TextBox1.Text) '
TextBox1.Text = "13-08-2007" as expected

end sub

and I have:

Private Sub UserForm_Activate()
.......
TextBox1.Text = Format(Range("J2").Value, "dd/mm/
yyyy") 'In cell J2 I have =Today()
.......
End Sub

Thanks ,

Mark




All times are GMT +1. The time now is 02:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com