0

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.

4
  • so you're saying there is no code behind the form that does anything with the form? Commented Mar 12, 2013 at 8:38
  • No, I said that the textbox instead of reading 03/01/2013 it reads 01/03/2013. I dont know why it changes the input data and I'd like to fix it. Thanks Commented Mar 12, 2013 at 8:50
  • okay, then let me rephrase: do you have any code behind the form? Can you please share it? It seems unlikely that the input simply changes without any code modifying it... :-) Commented Mar 12, 2013 at 8:57
  • Ok, let me modify the question Commented Mar 12, 2013 at 9:10

3 Answers 3

1

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

ThisWorkbook.Sheets("SUMUP").Range("D11") = Format(TextBox1.Value, "dd/MM/yyyy")
Sign up to request clarification or add additional context in comments.

Comments

1

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.

7 Comments

thanks, I think it will work it out. The first questions, I think, are above my knowledge in VBA
Since you are calling one of your sheets HIDDEN, i, for some reason, assumed you are saving your users input into a cell on a theoretically 'hidden' sheet. There is a way to avoid using extra, or hidden sheets by saving inputs into variables. You can read more about variables - im sure uncle google can help you out. One thing to remember - its to check your users input - make sure user is actually typing in date - not random numbers or sql injection lines etc.
thanks, I do appreciate your comment. You are right about the "Hidden" sheet. Yes, I'll check some info uncle google, XD.
I tried what you told me, but it doesn't work, I gave the format to cells, then I decided to use a public variable and use "txtb1 = TextBox1.Value" instead of "'ThisWorkbook.Sheets("Hidden").Range("D1").Value = TextBox1.Value", but it keeps changing the value, if I put in the textbox 05/01/2013, it processes "01/05/2013", but in the texbox you can see the original "05/01/2013". Any clue?.
look bud :) variables do not have brains - they are storage allocated in memory
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.