After update for date field.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hrprabhu
    New Member
    • May 2010
    • 83

    After update for date field.

    I have a form with a date field and a transaction number field.


    The transaction number is of the format 99678*06*10*012 34. The first five digits (99678) are source code. The next two digits (06) are the register number. The next two digits (10) are the year the transaction was input. Finally the last five digits (01234) are the transaction number.

    When I input the date I want the want the cursor to go to the transaction number field with the source code, register number and the year already input, rest in the 10th place.


    I.e., if the input date is 24-June-10, the string 99678*06*10* should be input and the cursor should be resting in the 10th position. How do it do it?


    I tried this.

    Code:
    Private Sub inputDate_AfterUpdate()
    transNo.Value = "99678*06* &CInt(Format(inputDate(),'yy'))"
    End Sub
    Thanks
  • colintis
    Contributor
    • Mar 2010
    • 255

    #2
    A correction to your current code first, you should place the closing double quote before the & CInt(...). Otherwise you will be seeing this code as part of your result as well. By including the cursor positioning code, it should be like this:
    Code:
    Private Sub inputDate_AfterUpdate() 
    
    transNo.Value = "99678*06*" & CInt(Format(inputDate(),'yy')) 
    
    transNo.SelStart = 10
    transNo.SelLength = 0
    
    End Sub
    The .SelStart is basically what you were requesting, while .SelLength specifies or determines the number of characters selected in a text box.

    An additional reminder, if your cursor is placing after the 3rd set of digits, then the .SelStart should be 12.

    Comment

    • hrprabhu
      New Member
      • May 2010
      • 83

      #3
      Thanks.

      It is working beautifully.

      Cheers

      Comment

      Working...