multiple input mask

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ezechiel
    New Member
    • Jul 2009
    • 53

    multiple input mask

    hi everyone..

    i read on another forum that it is possible to define multiple input masks for a textbox (for example).

    There is a textbox field where you can enter the name of a machine.
    The user should only have two possibilities:

    HOSTx-xxx vba: HOST9-99C ? like HOST2-45 or HOST9-245
    (C can be 'nothing', right or not?)

    or
    SRV000xxx like SRV000105

    So how can i combine two input masks?
    The following is not working..
    Code:
    Me.txt_computer.InputMask = "HOST9-99C;;_" Or "SRV000999;;_"
    Another question: how can I force the text HOST or SRV000?

    Thanks
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by ezechiel
    hi everyone..

    i read on another forum that it is possible to define multiple input masks for a textbox (for example).

    There is a textbox field where you can enter the name of a machine.
    The user should only have two possibilities:

    HOSTx-xxx vba: HOST9-99C ? like HOST2-45 or HOST9-245
    (C can be 'nothing', right or not?)

    or
    SRV000xxx like SRV000105

    So how can i combine two input masks?
    The following is not working..
    Code:
    Me.txt_computer.InputMask = "HOST9-99C;;_" Or "SRV000999;;_"
    Another question: how can I force the text HOST or SRV000?

    Thanks
    I do believe that you can only define a Single Input Mask which does nothing for your case. What you can do is to write code in the BeforeUpdate() Event of the Text Box that insures that only a few valid formats will be entered. If not, then the Update is cancelled.
    Code:
    Private Sub Text94_BeforeUpdate(Cancel As Integer)
    Dim txt As TextBox
    Dim intCharPos As Integer
    
    Set txt = Me![Text94]
    
    If txt Like "HOST9-[0-9][0-9]" Or txt Like "HOST9-[0-9][0-9][0-9]" _
                 Or txt Like "SRV000[0-9][0-9][0-9]" Then
    Else
      MsgBox "Invalid Entry" & vbCrLf & vbCrLf & "Valid Codes should be " & _
             "HOST9-xx, HOST9-xxX, or SRV000xxx where x is a Numeric Value.", _
              vbExclamation, "Entry Not Valid"
                Cancel = True
    End If
    End Sub

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Multiple Input Masks

      There is one point that I should clarify after careful consideration. You can define Multiple Input Masks based on the value of another Field, as in:
      Code:
      If Me![<Some Field>] = <Value> Then
        Me![<Another Field>].InputMask = "<Input Mask 1>"
      Else
        Me![<Another Field>].InputMask = "<Input Mask 2>"
      End If

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        I think ADezii has covered this well! You can assign multiple Input Masks, but only one at a time (as demonstrated in his second post) prior to entering data into the target control. I would think you would also have to insure that the target control was locked until whatever condition was met that led to a particular Input Mask being assigned.

        For the scenario given by the OP here, I would think that Validation code, executed after the data has been entered, such as ADezii's first post gives, would be the way to go.

        Linq ;0)>

        Comment

        • ezechiel
          New Member
          • Jul 2009
          • 53

          #5
          Ok,

          thanks for the answers people!! I think every solution has been covered here.
          You just made the first interesting post (with solution) on the internet concerning this problem!!! (I googled around a lot, but every time, people suggest to use two textboxes, add a field in DB or other stuff.)

          So, finally a couple of usefull answers! :D

          Thanks again!

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32659

            #6
            Originally posted by ezechiel
            So, finally a couple of useful answers! :D
            That's why I stuck around in the first place if truth be told. I had a couple of long-standing issues that I could find answers to anywhere.

            I remember Mary (msquared) was able to answer one for me from her own personal understanding, and another was answered too. Much to my surprise I admit. I'd pretty well given up hope of finding answers ever.

            Comment

            Working...