Results 1 to 5 of 5
  1. #1
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624

    Undo Typing in Unbound Textbox

    I am beginning to think what I want is not possible.



    I have an unbound textbox that is used to input search criteria to find record in subform.
    InputMask: 0000"A-"0000;0;_
    DefaultValue: Year(Date())

    Code for the textbox:
    Code:
    Private Sub tbxLabNum_BeforeUpdate(Cancel As Integer)With Me.ctrSampleList.Form.RecordsetClone
        .FindFirst "LabNum='" & Me.tbxLABNUM & "'"
        If .NoMatch = True Then
            MsgBox Me.tbxLABNUM & " is not valid Lab Number", , "EntryError"
            Me.tbxLABNUM.SelStart = 6
            Cancel = True
        Else
            Me.ctrSampleList.Form.Bookmark = .Bookmark
        End If
    End With
    End Sub
    This all works but decided it would be even better if I could undo the user's bad input. As is, the invalid input is retained by the textbox and user can't leave the textbox without hitting ESC key or typing valid entry. I know I could use a combobox but users like just entering the last 4 characters, rarely (except at beginning of new year) do they need to search for prior year record by typing the prefix . I have tried:

    1. The obvious - UNDO method, doesn't seem to do anything with unbound control
    2. Sendkeys "{ESC}" but then the entire default value is selected
    3. Setting the textbox value can't be done in BeforeUpdate
    4. The SelStart method is totally ignored in AfterUpdate and cursor sits at beginning of the prefix and user has to cursor right or mouse click to the suffix or type the entire value

    This is not a critical enhancement, just a 'would be nice', although users feel current behavior is tolerable.

    So can I have my cake and eat it too?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi June -

    Since the Textbox is unbound, it is not constrained by any underlying table properties, and you could reset it to Null or the default value. You could put the check in the the On Exit:

    Private Sub Text12_Exit(Cancel As Integer)
    If IsNull(Text12) Then Exit Sub
    MsgBox "Sorry - " & Me!Text12 & " is not valid. Try again"
    Me!Text12 = Year(Date)
    Text12.SelStart = 6
    Cancel = True

    End Sub


    This worked fine in a test, and I think does exactly what you want. I used your input mask, and the cursor goes right where it should.

    John
    Last edited by John_G; 08-28-2012 at 06:40 PM. Reason: change the example code

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Thanks for the suggestion John. Sounded good but unfortunately won't work with this form. More info:

    This form serves to:
    1. Filter/search records, form only allows records to be viewed in datasheet subform - no data entry/edit
    2. Initiate an assortment of tasks with single record or the subform's recordset by button click

    The TabStop property of all other controls is set to No. They must be clicked on or Alt+shortcut. Apparently, the Exit event is not triggered because there is nowhere to exit to. Focus stays on the textbox and the search does not happen.

    Think I have catch-22 conundrum.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi June -

    Odd behaviour. I created a little test form with only one control, an unbound text box, and the On Exit event did fire - but only if the text box had Tab Stop = Yes.

    "Focus stays on the textbox and the search does not happen."

    Looking at your code - if your text box tbxLabNum is the only control on the form with Tab stop = Yes, it seems to me reasonable the cursor won't move, because you would have to move it in code. Just executing the search won't move the cursor anywhere, will it? I do the same sort of thing, and I have to explicitly move the cursor to the subform.

    I can't see there being a difference in behaviour between A2003 and A2010 for something like that, but....

    John

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    That's right. The record in subform is selected and value in the first field of the record is selected but the typing cursor remains in the textbox on main form. I tried the Exit event, with a breakpoint, but it never triggered.

    So I just did the same test you did, a form with only the one control. The Exit event does run! So what can it be about my form?!?!?!

    Actually, the Exit event is not suitable anyway because it will trigger again if user leaves the textbox by selecting another control. Not pursuing this further. The current behavior is acceptable.
    Last edited by June7; 08-29-2012 at 10:56 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Unbound textbox in bound form
    By Evilferret in forum Forms
    Replies: 5
    Last Post: 08-15-2012, 01:26 PM
  2. Replies: 1
    Last Post: 02-29-2012, 04:46 PM
  3. Replies: 16
    Last Post: 10-13-2011, 07:52 AM
  4. Unbound textbox and report linked to vba
    By Shambler2 in forum Programming
    Replies: 7
    Last Post: 06-09-2011, 04:29 PM
  5. Display PASS or FAIL using Unbound textbox
    By Shambler2 in forum Reports
    Replies: 7
    Last Post: 06-02-2011, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums