Results 1 to 3 of 3

Thread: Access -- Using input mask as delimiter

  1. #1

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Access -- Using input mask as delimiter

    I am using an input mask to display my information as "99/99".

    When I display the contents of the textbox it appears as "1003" instead of "10/03". It also saves it this way to the database. I am trying to use the split function to break it up into 2 seperate numbers IE 10 and 03 so I can save it into the database as "10/03".

    The user can also enter the values as 10/3 or 1/1 or any variation, so I cannot simply split it per 2 digits.


    Does anyone know how to either save a textbox to a database including the mask, or does anyone know how to split the textbox contents by the delimiter?


    Thanks,
    kfcSmitty

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Access -- Using input mask as delimiter

    The following code will split the value in your testbox based on the position of the forward slash.


    VB Code:
    1. Private Sub Text8_AfterUpdate()
    2. Dim MasterString As String
    3. Dim SubString1 As String
    4. Dim SubString2 As String
    5.    
    6.     MasterString = Me.Text8
    7.    
    8.     'First check if the field has a forward slash
    9.     If InStr(1, MasterString, "/") = 0 Then
    10.         Me.Text8 = ""
    11.         Exit Sub
    12.     End If
    13.    
    14.     'Then Set the two substrings to the values to the left and right of the forward slash
    15.     SubString1 = Left(MasterString, InStr(1, MasterString, "/") - 1)
    16.     SubString2 = Mid(MasterString, InStr(1, MasterString, "/") + 1)
    17.    
    18.     'Just to prove that it works
    19.     'replace this with your code
    20.     MsgBox SubString1
    21.     MsgBox SubString2
    22. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Access -- Using input mask as delimiter

    You could also use the split function to populate the data into an array..

    VB Code:
    1. Dim Values() As String
    2.   If Instr(textbox1,"/") > 0 Then
    3.     Values = Split(textbox1,"/")
    4.     Msgbox Values(0)
    5.     Msgbox Values(1)
    6.   End If

    However, you may be better off placing the imput mask on the text box and the relevant field in the table below to

    00/00

    This will force data entry in the format of two digits followed by "/" and then two digits, if this is not entered then the user will receive a message to this affect
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width