none
date format in textbox userform RRS feed

  • Question

  • Hi

    I need date format when entering the dates in a userform textbox?

    I have no experience in this so i need full details.

    Below is the form i'm using.

    Please help me with a detailed code?

    Thanks


    Thanks you very much

    Wednesday, September 5, 2012 2:51 PM

Answers

  • Sure.Following will do that.

    Activecell.Value=DateSerial(TextYear.Value,TextMonth.Value,TextDay.Value)

    Activecell.NumberFormat="dd/mm/yy"

    I assumed the textbox name as TextYear for specifying year....and so for month,days

    If possible include some statement which will set focus to next box when current box is filled.


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, September 6, 2012 7:02 AM
    Answerer

All replies

  • What you mean by "date format when entering...."

    I think you want user to help with date entry.Instead you can use DatePicker control.

    or you can use 3 text box for each date.One text box for year,month,day.


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, September 6, 2012 5:56 AM
    Answerer
  • When you open the user form it should indicate the following in the two date text boxes:

    _ _/_ _/_ _ wereby the user can then just enter 060912 in the text box and once the commandbutton is pressed it will display the date as follow on the worksheet  06/09/12?

    Is that possible?


    Thanks you very much

    Thursday, September 6, 2012 6:48 AM
  • Sure.Following will do that.

    Activecell.Value=DateSerial(TextYear.Value,TextMonth.Value,TextDay.Value)

    Activecell.NumberFormat="dd/mm/yy"

    I assumed the textbox name as TextYear for specifying year....and so for month,days

    If possible include some statement which will set focus to next box when current box is filled.


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, September 6, 2012 7:02 AM
    Answerer
  • Thanks for your reply.

    However I need it in my vba code can you add me more details below is the current vba i'm using?

    Private Sub UserForm_Initialize()
    Dim cPar As Range
    Dim cBdc As Range
    Dim ws As Worksheet
    Set ws = Worksheets("LookupLists")

    For Each cPar In ws.Range("PartIDList")
      With Me.PlantNr
        .AddItem cPar.Value
        
      End With
    Next cPar

    For Each cBdc In ws.Range("BDCodes")
      With Me.BDCode
        .AddItem cBdc.Value
       
      End With
    Next cBdc

    Me.PlantNr.Value = ""
    Me.StartDate.Value = ""
    Me.StartTime.Value = ""
    Me.EndDate.Value = ""
    Me.PlantNr.SetFocus

    End Sub


    Thanks you very much

    Thursday, September 6, 2012 7:16 AM
  • You should use the 2 statement I suggested in the txtbox event not in form_initialize event.


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, September 6, 2012 7:22 AM
    Answerer
  • How do i do that as mentioned i'm very new to this and i have started now and got addicted to it... :)

    Thanks you very much

    Thursday, September 6, 2012 7:25 AM
  • http://www.sendspace.com/file/kq451o

    I hope it will help you start.....


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, September 6, 2012 8:36 AM
    Answerer
  • You can use mask for autoformat textbox

    Take look on this case: maska-dla-kontrolki-textbox


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Thursday, September 6, 2012 10:03 AM
    Answerer