Results 1 to 8 of 8
  1. #1
    Dan is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    15

    Question Changing Bound Text Box Border Width Property Screws Up Tab Order and Value Display

    Hi, I am using Access 2007. I have module sub that is passed the
    form's name and it checks to see if control is a text box that just
    received focus and if so thickens it border to queue user where
    insertion pointer is. The problem is as the user tabs from control
    to control the text will disappear in the text box that got the focus
    and reappear on exit from control or a mouse click in it. In addition
    the tab order no longing works either. Here is the code:

    ' This function, HighlightTextbox(), highlights a textbox border to
    indicate it has the Focus and de-highlights
    ' previous object focus if textbox. Since Access cannot trigger this
    function on the form level, a call must be made
    ' in each textbox on the form.
    Public Sub HighlightTextbox(strCallingForm As String)

    Dim ctrlActive As Control
    Dim strActiveControlSource As String
    Dim ctrlPrev As Control
    Dim strPrevControlSource As String
    Dim intRetval As Integer



    On Error GoTo HighlightTextbox_Error

    'If Forms(strCallingForm).Visible = True Then

    'Forms(strCallingForm).AllowEdits = False

    Set ctrlActive = Screen.ActiveControl

    If TypeOf ctrlActive Is TextBox Then
    'ctrlActive.Enabled = False
    'strActiveControlSource = ctrlActive.ControlSource
    'ctrlActive.ControlSource = ""
    'ctrlActive.Locked = True
    ctrlActive.BorderWidth = 2
    intRetval = DoEvents()
    Debug.Print "active", ctrlActive.Name
    End If

    Set ctrlPrev = Screen.PreviousControl
    If TypeOf ctrlPrev Is TextBox Then
    'ctrlPrev.Enabled = False
    'strPrevControlSource = ctrlPrev.ControlSource
    'ctrlPrev.ControlSource = ""
    'ctrlPrev.Locked = True
    ctrlPrev.BorderWidth = 0
    intRetval = DoEvents()
    Debug.Print "previous", ctrlPrev.Name
    End If

    Debug.Print Time, ctrlActive.Name, ctrlPrev.Name
    'ctrlActive.Enabled = True
    'ctrlPrev.Enabled = True
    'ctrlActive.ControlSource = strActiveControlSource
    'ctrlPrev.ControlSource = strPrevControlSource
    'ctrlActive.Locked = False
    'ctrlPrev.Locked = False
    'Forms(strCallingForm).AllowEdits = False

    'End If

    Exit Sub

    HighlightTextbox_Error:

    Exit Sub

    End Sub


    How can I get Access to behave properly? I am assuming I have to
    suspend the Control Source in some fashion but tried many ways with no
    luck. TIA

  2. #2
    goodguy is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Zanzibar, Tanzania
    Posts
    229
    Why have you commented out parts of the code?
    Are they commented as such in your source?

  3. #3
    Dan is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    15
    Quote Originally Posted by goodguy View Post
    Why have you commented out parts of the code?
    Are they commented as such in your source?
    Those are steps I tried to disable the bound text box from bound behavior. This bug is only reproducible with bound text boxes.

  4. #4
    goodguy is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Zanzibar, Tanzania
    Posts
    229
    Code:
    strPrevControlSource = ctrlPrev.ControlSource
    Why are you modifying the controlsource property in code?
    This is the crux of your problem. Controlsource should best be set at runtime and not altered afterward unless you are a pro with VBA.

  5. #5
    Dan is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    15
    It was just a test to see if it would prevent the problem. Ignore the remarked executable code.

  6. #6
    goodguy is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Zanzibar, Tanzania
    Posts
    229
    Please attach your db.

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    1. You don't need to pass the form's name. You aren't even using it.

    2. The procedure should be a FUNCTION and not a SUB if you want to set the event property to =HighlightTextBox()



    3. This works for me but I'm using Access 2003 at the moment at work but you might want to double check that your text boxes don't have the backstyle set to transparent which could be why the text appears to disappear when the focus is set on it.


    Code:
    Public Function HighlightTextbox()
        Dim ctrlActive As Control
        Dim strActiveControlSource As String
        Dim ctrlPrev As Control
        Dim strPrevControlSource As String
        Dim intRetval As Integer
        On Error GoTo HighlightTextbox_Error
     
        Set ctrlActive = Screen.ActiveControl
        If TypeOf ctrlActive Is TextBox Then
            ctrlActive.BorderWidth = 6
            intRetval = DoEvents()
            Debug.Print "active", ctrlActive.Name
        End If
        Set ctrlPrev = Screen.PreviousControl
        If TypeOf ctrlPrev Is TextBox Then
            ctrlPrev.BorderWidth = 0
            intRetval = DoEvents()
            Debug.Print "previous", ctrlPrev.Name
        End If
        Debug.Print Time, ctrlActive.Name, ctrlPrev.Name
    ExitHere:
         Exit Function
    HighlightTextbox_Error:
     
                MsgBox "Error " & Err.Number & " - " & " (" & Err.Description & ") in procedure HighlightTextbox "
                Resume ExitHere
                Resume
    End Function
    Now it may be that it will work better to have another function which will set the control back to normal instead of trying to do it here and you would put that call in the control's Lost Focus event.

  8. #8
    Dan is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    15
    Bob thanks for tips but it did not clear up the problem with Access 2007. My Borderstyles are set to SOLID so that was not the issue. Also, changing the SUB to a FUNCTION and referencing it in the EVENT list did not clear up issue.

    By changing the borderwidth in the GotFocus() and LostFocus() events the disappearing text value problem is fixed so that problem has something to do with jumping out to a Module function call. Big pain to change all the values in each event though!

    I still have the remaining TAB issue though.

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

Similar Threads

  1. Text box width/bring to front and Checkbox
    By SorenIX in forum Programming
    Replies: 16
    Last Post: 06-22-2011, 06:07 PM
  2. export query to fixed width text
    By eladz949 in forum Import/Export Data
    Replies: 1
    Last Post: 02-08-2011, 07:28 AM
  3. Removing bound property of combo box for certain users
    By CompostKid in forum Programming
    Replies: 4
    Last Post: 07-27-2010, 01:26 PM
  4. Replies: 0
    Last Post: 11-13-2009, 10:18 AM
  5. Access 2003, sort order property of a form
    By Rick West in forum Forms
    Replies: 11
    Last Post: 09-17-2009, 08:28 PM

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