Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command buttons stay highlighted even after selecting another control

Status
Not open for further replies.

cwadams1955

Programmer
Jan 21, 2008
52
CA
Hi,

I have a continuous form which opens a single table for editing. In the header of the form are two command buttons which filter the records as "uncompleted only" or "all records", based on a single field in the table. The form detail contains a command button to "filter on selection" in a second field in the table, based on the data in the selected record. The commands work perfectly, but whatever button is clicked remains highlighted with a yellow border, even if a different control is selected. I've never noticed this behavior before with other forms, and was wondering if there is any way to turn off this highlighting in VBA? Searches haven't turned up any info. Thanks.
 
What is the VBA code behind your buttons? If I had to guess, there is some VBA code somewhere that is setting that formatting. Whatever code that is needs to be commented out, at least, if you don't want the formatting effects. Or if you just want to move the focus, then you could add additional code that undoes the formatting on the button, and formats the first text box, for instance... and so on..

--

"If to err is human, then I must be some kind of human!" -Me
 
Code for the "show uncompleted only" filter button:

Code:
Private Sub btnGetRecords_Click()
    On Error GoTo Err_btnGetRecords_Click

    Dim strSQL As String, strMsg As String

    If Nz(Me.txtCompletedBy, "") = "" Then
        Me.txtCompletedBy.SetFocus
        strMsg = "Must Enter Completed-By"
        Err.Raise vbObjectError + 1005, , strMsg
    End If
    
    If IsNull(Me.cboProjectNo) Then
        Me.cboProjectNo.SetFocus
        strMsg = "Must Select Project Number"
        Err.Raise vbObjectError + 1005, , strMsg
    End If

    If IsNull(Me.cboRequestType) Then
        Me.cboRequestType.SetFocus
        strMsg = "Must Select Request Type"
        Err.Raise vbObjectError + 1005, , strMsg
    End If

    If IsNull(Me.cboRequestID) Then
        Me.cboRequestID.SetFocus
        strMsg = "Must Select Request ID"
        Err.Raise vbObjectError + 1005, , strMsg
    End If

    strSQL = "SELECT * FROM tblLabTestDetail " & _
            "WHERE ([ProjectNo] = '" & Me.cboProjectNo.Value & _
            "') AND ([RequestType] = '" & Me.cboRequestType & _
            "') AND ([RequestID] = '" & Me.cboRequestID & _
            "') AND (([Completed] IS NULL) OR ([Completed] <> 1))"
    
    Me.RecordSource = strSQL
    Me.Requery
    
Exit_btnGetRecords_Click:
    Exit Sub

Err_btnGetRecords_Click:
    
    MsgBox Err.Description, vbOKOnly, "ERROR!"
    Resume Exit_btnGetRecords_Click

End Sub

Code for the "show all records" filter button:

Code:
Private Sub btnShowAll_Click()
    On Error GoTo Err_btnShowAll_Click

    Dim strSQL As String, strMsg As String

    If Nz(Me.txtCompletedBy, "") = "" Then
        Me.txtCompletedBy.SetFocus
        strMsg = "Must Enter Completed-By"
        Err.Raise vbObjectError + 1005, , strMsg
    End If
    
    If IsNull(Me.cboProjectNo) Then
        Me.cboProjectNo.SetFocus
        strMsg = "Must Select Project Number"
        Err.Raise vbObjectError + 1005, , strMsg
    End If

    If IsNull(Me.cboRequestType) Then
        Me.cboRequestType.SetFocus
        strMsg = "Must Select Request Type"
        Err.Raise vbObjectError + 1005, , strMsg
    End If

    If IsNull(Me.cboRequestID) Then
        Me.cboRequestID.SetFocus
        strMsg = "Must Select Request ID"
        Err.Raise vbObjectError + 1005, , strMsg
    End If

    strSQL = "SELECT * FROM tblLabTestDetail " & _
            "WHERE ([ProjectNo]='" & Me.cboProjectNo.Value & _
            "' AND [RequestType]='" & Me.cboRequestType & _
            "' AND [RequestID]='" & Me.cboRequestID & "')"
    
    Me.RecordSource = strSQL
    Me.Requery
    
Exit_btnShowAll_Click:
    Exit Sub

Err_btnShowAll_Click:
    
    MsgBox strMsg, vbOKOnly, "ERROR!"
    Resume Exit_btnShowAll_Click

End Sub

Code for the "filter on selection" button:

Code:
Private Sub btnFilterCharges_Click()
On Error GoTo Err_btnFilterCharges_Click

    Me.ChargeCode.SetFocus
    DoCmd.RunCommand acCmdFilterBySelection

Exit_btnFilterCharges_Click:
    Exit Sub

Err_btnFilterCharges_Click:
    MsgBox Err.Description
    Resume Exit_btnFilterCharges_Click
    
End Sub

There's nothing I'm aware of that specifically sets the formatting of any of the controls. Any fields that are invisible are *always* invisible, no foreground or background colors, sizes, locations, etc are being changed.
 
Hmm, is there any other Form level event code? Perhaps a Form_OnUpdate or ...Change event?

--

"If to err is human, then I must be some kind of human!" -Me
 
No, the only form level event is the OnOpen:

Code:
Private Sub Form_Open(Cancel As Integer)

    Me.txtCompletedBy.SetFocus
    
End Sub

which only makes sure that the cursor moves to the correct field to start. All other events are control-level events, and none do any formatting. Mostly, they just set SQL statements to narrow down the record selections, except for the "Completed" field - inside its "AfterUpdate" event, it automatically saves the record, then calls a sub which runs a SQL stored procedure to update the count of completed records in another table.

Code:
Private Sub Completed_AfterUpdate()
    On Error GoTo Err_Completed_AfterUpdate

    Me.TestCompletedBy = Me.txtCompletedBy
    Me.TestCompDate = Date
    
    On Error Resume Next
    Me.Dirty = False
    On Error GoTo Err_Completed_AfterUpdate
    
    Call UpdateBillRecords
    
Exit_Completed_AfterUpdate:
    Exit Sub

Err_Completed_AfterUpdate:
    MsgBox Err.Description
    Resume Exit_Completed_AfterUpdate
    
End Sub
 
Hmm, another question... Is this Access 2007? If so, are you looking at the form in "Form View" or possibly in "Layout View"? If it's in Layout View, that'd explain it, but I imagine it's not that easy, either. [wink]

--

"If to err is human, then I must be some kind of human!" -Me
 
Nope. Access 2003, and it's in Form View. This is not a really big deal since all the functions are working properly, but my concern is that it might confuse the end users - I can barely get them to understand what buttons are for to start with. :-(
 
Believe me, I know what you're talking about. [wink]

Either way, there's got to be an answer.

If nothing else, I'd do a search through all the control and form properties if necessary. It's got to be either an object itself or a form property that you're seeing. Once you can locate it, you can just add in code to change/select it if you can't permanently fix it without the code.

--

"If to err is human, then I must be some kind of human!" -Me
 
No, they're just plain control buttons - I went back and double-checked. Just out of curiosity, I also checked a different form which has a command button used for a nearly identical task, and that button does not retain the highlighting once the focus moves away from it. Now, there *is* one difference which just occurred to me: the other button displays text, while each of the buttons in question on this new form displays one of the "filter" graphics.

(Tries something...)

Sure enough, if I remove the image from the button, the highlight goes away when the focus moves. Huh. How about that. Is there a "screams while beating head on desk" emoticon?? B-(

Thanks, all. I'd never noticed this behavior before.
 
And this one would fit as well...
[hairpull] [ignore][hairpull][/ignore]

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top