UnBound Combo Box Behaviour

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • prakashwadhwani@gmail.com

    UnBound Combo Box Behaviour

    I have an unbound combo box in the form header. I have used an input
    mask "CCCC" 40 times to limit the max number of characters to 40.

    When I tab into the combo box & press a character say "K" for example,
    the entire first match gets filled in the combo box and the cursor
    goes to the last character of the combo box. So I can't effectively
    search for a "KI" until I backspace the entire entry which has got
    filled in.

    Once i remove the input mask the combo box behaves normally. However I
    need the input mask to limit the max number of characters input to 40.
    Also, the combo box "limit to list" property is set to false so the
    user can select an existing value from the combo box + add/delete/
    modify the combo box contents.

    Can anyone please help.

    Thx & Best Rgds,
    Prakash.
  • Larry Linson

    #2
    Re: UnBound Combo Box Behaviour

    Obviously, the interaction with the Input Mask is the cause of your problem.

    There are other ways to limit the number of characters... you can put a test
    for length in the BeforeUpdate event and cancel the update if it is too
    long. Some of the other ways you could use can be confusing, at best, and
    irritating at worst, with a Combo, so I don't suggest those -- but if
    catching the over-lengthy entry after it is too long is not to your liking,
    you could search the newsgroup archives on KeyPress for a different
    approach.

    There are other, more complex approaches that one might use to try to tailor
    the user experience, but they will lose the built-in "AutoExpand " capability
    that lets you search the list so easily.

    Larry Linson
    Microsoft Office Access MVP


    <prakashwadhwan i@gmail.comwrot e in message
    news:225c0c39-7f7d-473f-b84e-4a95477027c2@s1 2g2000prg.googl egroups.com...
    >I have an unbound combo box in the form header. I have used an input
    mask "CCCC" 40 times to limit the max number of characters to 40.
    >
    When I tab into the combo box & press a character say "K" for example,
    the entire first match gets filled in the combo box and the cursor
    goes to the last character of the combo box. So I can't effectively
    search for a "KI" until I backspace the entire entry which has got
    filled in.
    >
    Once i remove the input mask the combo box behaves normally. However I
    need the input mask to limit the max number of characters input to 40.
    Also, the combo box "limit to list" property is set to false so the
    user can select an existing value from the combo box + add/delete/
    modify the combo box contents.
    >
    Can anyone please help.
    >
    Thx & Best Rgds,
    Prakash.

    Comment

    • CDMAPoster@fortunejames.com

      #3
      Re: UnBound Combo Box Behaviour

      On Mar 5, 11:02 am, "Larry Linson" <boun...@localh ost.notwrote:
      Obviously, the interaction with the Input Mask is the cause of your problem.
      >
      There are other ways to limit the number of characters... you can put a test
      for length in the BeforeUpdate event and cancel the update if it is too
      long. Some of the other ways you could use can be confusing, at best, and
      irritating at worst, with a Combo, so I don't suggest those -- but if
      catching the over-lengthy entry after it is too long is not to your liking,
      you could search the newsgroup archives on KeyPress for a different
      approach.
      >
      There are other, more complex approaches that one might use to try to tailor
      the user experience, but they will lose the built-in "AutoExpand " capability
      that lets you search the list so easily.
      >
       Larry Linson
       Microsoft Office Access MVP
      Larry,

      I agree that using a method other than the Input Mask for limiting the
      length of the text in the combobox is good advice. Perhaps you missed
      the word "unbound" or use bound forms exclusively. The BeforeUpdate/
      Cancel is, if I remember correctly, a common way to validate bound
      forms. Typically, validation for unbound forms is done in the
      AfterUpdate event. However, the method I use for that purpose
      validates in neither event.

      Here's what I use to limit the length of entries in comboboxes:

      'code behind form
      Private Sub cbxComboName_Ke yPress(KeyAscii As Integer)
      KeyAscii = LimitCombo(KeyA scii, cbxComboName, 50)
      End Sub

      'module code
      Public Function LimitCombo(KeyA scii As Integer, cbxCombo As ComboBox,
      intMax As Integer) As Integer
      'If the field has reached its maximum then return 0
      LimitCombo = KeyAscii
      cbxCombo.SetFoc us
      If Len(cbxCombo.Te xt) = intMax Then
      If KeyAscii <8 Then LimitCombo = 0
      End If
      End Function

      That will limit the contents of the combobox to 50 characters. If the
      50 character limit is reached, the combobox ignores any more text.
      Letting KeyAscii = 8 through allows the user to delete the last
      character if they reach the limit and made a mistake on the final
      character. This method should work on bound forms also and preserve
      AutoExpand, but check to be sure.

      James A. Fortune
      CDMAPoster@Fort uneJames.com

      Comment

      • CDMAPoster@fortunejames.com

        #4
        Re: UnBound Combo Box Behaviour

        On Mar 5, 2:08 pm, CDMAPos...@fort unejames.com wrote:
        However, the method I use for that purpose validates in neither event.
        I just tried pasting in text that was longer than the limit, so
        perhaps use the method in combination with your normal validation
        (i.e., check the length there also) or preclude ways to get around the
        method's limitations.

        James A. Fortune
        CDMAPoster@Fort uneJames.com

        Comment

        • prakashwadhwani@gmail.com

          #5
          Re: UnBound Combo Box Behaviour

          On Mar 5, 11:20 pm, CDMAPos...@fort unejames.com wrote:
          On Mar 5, 2:08 pm, CDMAPos...@fort unejames.com wrote:
          >
          However, the method I use for that purpose validates in neither event.
          >
          I just tried pasting in text that was longer than the limit, so
          perhaps use the method in combination with your normal validation
          (i.e., check the length there also) or preclude ways to get around the
          method's limitations.
          >
          James A. Fortune
          CDMAPos...@Fort uneJames.com

          I'm sorry James, but please excuse my lack of Access knowledge. I sort
          of understood the code of your previous post, but how do I check the
          length when the user has pasted code into the combo box ? In which
          event would I test and how ?

          Thx for the help,
          Prakash.

          Comment

          • Larry Linson

            #6
            Re: UnBound Combo Box Behaviour


            <prakashwadhwan i@gmail.comwrot e in message
            news:eeba067f-e36d-4a6c-bdd6-ae37d8969011@m3 4g2000hsc.googl egroups.com...
            On Mar 5, 11:20 pm, CDMAPos...@fort unejames.com wrote:
            >On Mar 5, 2:08 pm, CDMAPos...@fort unejames.com wrote:
            >>
            However, the method I use for that purpose validates in neither event.
            >>
            >I just tried pasting in text that was longer than the limit, so
            >perhaps use the method in combination with your normal validation
            >(i.e., check the length there also) or preclude ways to get around the
            >method's limitations.
            >>
            >James A. Fortune
            >CDMAPos...@For tuneJames.com
            >
            >
            I'm sorry James, but please excuse my lack of Access knowledge. I sort
            of understood the code of your previous post, but how do I check the
            length when the user has pasted code into the combo box ? In which
            event would I test and how ?
            Jim's correct -- the AfterUpdate event is the proper place for the code. The
            following code works for me, to replace however many characters are typed or
            pasted into the Combo Box with just the first five. (My clients do not
            expect their applications to "coddle" their users by being overly
            solicitous -- if there's a limit, it does not have to be detected at the
            first keystroke beyond that limit. They figure, I am sure, that typing
            several extra characters and having them disappear is an incentive for the
            user to learn and abide by the limit if they want to avoid the extra
            typing.)

            The AfterUpdate event does not fire until you press enter, or tab, or click
            out of the Combo Box.

            Private Sub cboName_AfterUp date()
            If Len(cboName.Tex t) 5 Then
            Me.cboName = Left(Me.cboName .Text, 5)
            End If
            End Sub

            Larry Linson
            Microsoft Office Access MVP


            Comment

            • CDMAPoster@fortunejames.com

              #7
              Re: UnBound Combo Box Behaviour

              On Mar 5, 10:13 pm, prakashwadhw... @gmail.com wrote:
              I'm sorry James, but please excuse my lack of Access knowledge. I sort
              of understood the code of your previous post, but how do I check the
              length when the user has pasted code into the combo box ?  In which
              event would I test and how ?
              >
              Thx for the help,
              Prakash.
              Larry is correct about the event and the viability of his psychology.
              The way the code I posted works is that when the limit is reached, the
              user hits a metaphorical wall. A KeyAscii value of zero gets ignored
              and all the other KeyAscii values get through. Thus, when the limit
              is reached, all further keystrokes get ignored except for the
              backspace character, whose ASCII value is 8. This prevents the user
              from typing more characters than the field allows, but does not
              prevent entering too many characters via other means. The editing
              doesn't fire the AfterUpdate event until the editing is complete. If
              someone gets around the system by pasting in more characters than the
              limit, the AfterUpdate event can catch it then. Catching the length
              at the keystroke level is a little awkward until users get used to
              it. Using Larry's idea of simply using the AfterUpdate event isn't
              perfect either. Maybe the KeyPress event could be used to pop up a
              warning when the limit is reached that specifies the number of
              characters allowed in the field instead of erecting a wall. The
              AfterUpdate code can stay in case they flaunt the warning or try to
              get around the system. It is also possible to code yet more events in
              attempt to close all the loopholes, but usually a workable arrangement
              can be found before that point is reached.

              James A. Fortune
              CDMAPoster@Fort uneJames.com

              Comment

              • prakashwadhwani@gmail.com

                #8
                Re: UnBound Combo Box Behaviour

                On Mar 7, 12:38 am, CDMAPos...@fort unejames.com wrote:
                On Mar 5, 10:13 pm, prakashwadhw... @gmail.com wrote:
                >
                I'm sorry James, but please excuse my lack of Access knowledge. I sort
                of understood the code of your previous post, but how do I check the
                length when the user has pasted code into the combo box ? In which
                event would I test and how ?
                >
                Thx for the help,
                Prakash.
                >
                Larry is correct about the event and the viability of his psychology.
                The way the code I posted works is that when the limit is reached, the
                user hits a metaphorical wall. A KeyAscii value of zero gets ignored
                and all the other KeyAscii values get through. Thus, when the limit
                is reached, all further keystrokes get ignored except for the
                backspace character, whose ASCII value is 8. This prevents the user
                from typing more characters than the field allows, but does not
                prevent entering too many characters via other means. The editing
                doesn't fire the AfterUpdate event until the editing is complete. If
                someone gets around the system by pasting in more characters than the
                limit, the AfterUpdate event can catch it then. Catching the length
                at the keystroke level is a little awkward until users get used to
                it. Using Larry's idea of simply using the AfterUpdate event isn't
                perfect either. Maybe the KeyPress event could be used to pop up a
                warning when the limit is reached that specifies the number of
                characters allowed in the field instead of erecting a wall. The
                AfterUpdate code can stay in case they flaunt the warning or try to
                get around the system. It is also possible to code yet more events in
                attempt to close all the loopholes, but usually a workable arrangement
                can be found before that point is reached.
                >
                James A. Fortune
                CDMAPos...@Fort uneJames.com


                Larry & James ... thank you very much for your replies. Sorry, I was
                posted in the interior during the past week & could not reply.

                If the user has exceeded an input length of 40 characters, I'd like to
                flash a message via a msgbox & set focus back to that combo box.
                However, much as I try, the focus moves back to the next control. Is
                there anything I'm doing wrong here ?

                Here's my code:

                Private Sub txt_RcdFm_PdTo_ AfterUpdate()
                If Len(txt_RcdFm_P dTo.Text) 40 Then
                MsgBox "Length of 'PAID TO' cannot exceed 40 characters"
                Me.txt_RcdFm_Pd To = Left(Me.txt_Rcd Fm_PdTo.Text, 40) '
                SELECT characters exceeding 40 here
                Me.txt_RcdFm_Pd To.SetFocus
                End If
                End Sub


                What I'd like now is the cursor should go back to txt_RcdFm_PdTo and
                the number of characters exceeding 40 should be SELECTED. i.e. if the
                user has entered 55 characters, the last 15 characters should be
                highlighted.

                I think I might just have to use the beforeupdate event here.

                Thx for all help.

                Rgds,
                Prakash.

                Comment

                • CDMAPoster@fortunejames.com

                  #9
                  Re: UnBound Combo Box Behaviour

                  On Mar 11, 11:43 am, prakashwadhw... @gmail.com wrote:
                  Larry & James ... thank you very much for your replies. Sorry, I was
                  posted in the interior during the past week & could not reply.
                  >
                  If the user has exceeded an input length of 40 characters, I'd like to
                  flash a message via a msgbox & set focus back to that combo box.
                  However, much as I try, the focus moves back to the next control. Is
                  there anything I'm doing wrong here ?
                  >
                  Here's my code:
                  >
                  Private Sub txt_RcdFm_PdTo_ AfterUpdate()
                       If Len(txt_RcdFm_P dTo.Text) 40 Then
                          MsgBox "Length of  'PAID TO'  cannot exceed 40 characters"
                          Me.txt_RcdFm_Pd To = Left(Me.txt_Rcd Fm_PdTo.Text, 40)  '
                  SELECT characters exceeding 40 here
                          Me.txt_RcdFm_Pd To.SetFocus
                       End If
                  End Sub
                  >
                  What I'd like now is the cursor should go back to  txt_RcdFm_PdTo  and
                  the number of characters exceeding 40 should be SELECTED. i.e. if the
                  user has entered 55 characters, the last 15 characters should be
                  highlighted.
                  >
                  I think I might just have to use the beforeupdate event here.
                  >
                  Thx for all help.
                  >
                  Rgds,
                  Prakash.
                  Use the SelStart and SelLength properties of the textbox after using
                  SetFocus, to highlight the text you want.

                  Something like (i.e., air code):

                  Private Sub txt_RcdFm_PdTo_ AfterUpdate()
                  Const PdMAX = 40
                  If Len(Nz(Me!txt_R cdFm_PdTo.Value , "")) PdMAX Then
                  'omit Me.txt_RcdFm_Pd To = Left( ... so you have something to select
                  With Me!txtRcdFm_PdT o
                  .SetFocus
                  .SelStart = PdMAX + 1
                  .SelLength = Len(.Value) - PdMAX
                  End With
                  End If
                  End Sub

                  James A. Fortune
                  CDMAPoster@Fort uneJames.com

                  Comment

                  • prakashwadhwani@gmail.com

                    #10
                    Re: UnBound Combo Box Behaviour

                    On Mar 11, 9:40 pm, CDMAPos...@fort unejames.com wrote:
                    On Mar 11, 11:43 am, prakashwadhw... @gmail.com wrote:
                    >
                    >
                    >
                    Larry & James ... thank you very much for your replies. Sorry, I was
                    posted in the interior during the past week & could not reply.
                    >
                    If the user has exceeded an input length of 40 characters, I'd like to
                    flash a message via a msgbox & set focus back to that combo box.
                    However, much as I try, the focus moves back to the next control. Is
                    there anything I'm doing wrong here ?
                    >
                    Here's my code:
                    >
                    Private Sub txt_RcdFm_PdTo_ AfterUpdate()
                    If Len(txt_RcdFm_P dTo.Text) 40 Then
                    MsgBox "Length of 'PAID TO' cannot exceed 40 characters"
                    Me.txt_RcdFm_Pd To = Left(Me.txt_Rcd Fm_PdTo.Text, 40) '
                    SELECT characters exceeding 40 here
                    Me.txt_RcdFm_Pd To.SetFocus
                    End If
                    End Sub
                    >
                    What I'd like now is the cursor should go back to txt_RcdFm_PdTo and
                    the number of characters exceeding 40 should be SELECTED. i.e. if the
                    user has entered 55 characters, the last 15 characters should be
                    highlighted.
                    >
                    I think I might just have to use the beforeupdate event here.
                    >
                    Thx for all help.
                    >
                    Rgds,
                    Prakash.
                    >
                    Use theSelStartand SelLength properties of the textbox after using
                    SetFocus, to highlight the text you want.
                    >
                    Something like (i.e., air code):
                    >
                    Private Sub txt_RcdFm_PdTo_ AfterUpdate()
                    Const PdMAX = 40
                    If Len(Nz(Me!txt_R cdFm_PdTo.Value , "")) PdMAX Then
                    'omit Me.txt_RcdFm_Pd To = Left( ... so you have something to select
                    With Me!txtRcdFm_PdT o
                    .SetFocus
                    .SelStart= PdMAX + 1
                    .SelLength = Len(.Value) - PdMAX
                    End With
                    End If
                    End Sub
                    >
                    James A. Fortune
                    CDMAPos...@Fort uneJames.com

                    Thx James for the invaluable advice & code. Somehow though after
                    fiddling around, I opted to go with Allen Browne's code from his site:
                    How to limit the number of characters that can be typed into a text box in a Microsoft Access database, even where the box is not bound to a field that limits its length.


                    I think it makes the Access unbound Text Box behave almost like a
                    bound text box.

                    What still beats me is why don't the MS developers make a small
                    property for an unbound textbox which would enable the user to specify
                    the maximum length of a string. eg: txt_MyTextbox.M axLength=40

                    Am I wrong in thinking along these lines ?

                    Thanks though to all who have helped.

                    Best Rgds,
                    Prakash.

                    Comment

                    Working...