themolestones
themolestones

Reputation: 203

Wrong Textbox in a Form VBA

I am doing a form and I am finding myself with a weird problem with the TextBox.

I ask the user to insert some data and when it does, the TextBox changes the data.

An example, if the user inserts: 03/01/2013 and then the runs the form, the form instead to perform the code with the original data changes it, 01/03/2013.

I realized that always changes the day and the month, but never the year.

Extra information, I never "told" the form that the data it is gonna process it is a date.

I am struggling to make it work it out, so any help will be grateful.

If extra info is needed, please let me know it.

Code:

Private Sub CommandButton1_Click()

ThisWorkbook.Sheets("Hidden").Range("D1").Value = TextBox1.Value

ThisWorkbook.Sheets("Hidden").Range("D2").Value = TextBox2.Value

If TextBox1.Value < TextBox2.Value Then

    If TextBox1.Value = "" Or TextBox2.Value = "" Then

        MsgBox "...", vbExclamation, "  ..."

    Else

    Run "macro"

    ThisWorkbook.Sheets("SUMUP").Range("D11").Value = TextBox1.Value

    ThisWorkbook.Sheets("SUMUP").Range("D12").Value = TextBox2.Value

    End If

Else

MsgBox "..." & vbCrLf & "...", vbExclamation, "  ..."

End If

End Sub

Thanks.

Upvotes: 0

Views: 519

Answers (3)

George Marcus
George Marcus

Reputation: 16

You have to change the date format of your system in order to accept the input format of your vba form. Go to

Start>Control panel>Clock

Language and Date, under Region and Language select Change date, time or number format. Under date and time format select the drop-down in front of Short Date then select dd-mmm-yy. Do thesame on long date and select dddd,mmmm dd,yyyy. I hope this would be helpful

Upvotes: 0

user2140173
user2140173

Reputation:

The most common issue related to your description:
you may be saving the users input into a cell. If So, please check the formatting of that cell.

Please provide more info on how the users input is stored. What datatype variable are you using to store the users input? What is the migration process for the input?

Post-Edit:

Format your cells ( simplest solution )

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

P.S. You can store your users input in variables:

    Dim txtb1, txtb2 As String

    'ThisWorkbook.Sheets("Hidden").Range("D1").Value = TextBox1.Value
    'ThisWorkbook.Sheets("Hidden").Range("D2").Value = TextBox2.Value
    '
    ' instead of storing the value in cell, use variables ( now youre not going to need a "hidden" sheet
    '
    txtb1 = TextBox1.Value
    txtb2 = TextBox2.Value

Hope this helps.

Upvotes: 1

www
www

Reputation: 4391

It's a VBA :]. Just convert to string by:

ThisWorkbook.Sheets("SUMUP").Range("D11") = Format(TextBox1.Value, "dd/MM/yyyy")

Upvotes: 1

Related Questions