bejhan
asked on
Set control .enabled property to false, control .enabled property still true
I have implemented custom navigation buttons, below is my button update code.
If .BOF Then
cmdMovePrevious.Enabled = False
Else
cmdMovePrevious.Enabled = True
End If
After cmdMovePrevious.Enabled = False is executed cmdMovePrevious.enabled is still true. Why is this happening, below I have almost identical code for cmdMoveNext and it does not give me any problems.
2.bmp
3.bmp
If .BOF Then
cmdMovePrevious.Enabled = False
Else
cmdMovePrevious.Enabled = True
End If
After cmdMovePrevious.Enabled = False is executed cmdMovePrevious.enabled is still true. Why is this happening, below I have almost identical code for cmdMoveNext and it does not give me any problems.
Public Sub EnableDisableButtons()
On Error Resume Next
txtRecordNumber = frmNavigate.CurrentRecord
If Err <> 0 Then Exit Sub
If frmNavigate.RecordsetClone.RecordCount > 0 Then frmNavigate.RecordsetClone.MoveLast
If frmNavigate.NewRecord = True Then
txtRecordNumber = frmNavigate.RecordsetClone.RecordCount + 1
lblTotalRecords.Caption = " of " & frmNavigate.RecordsetClone.RecordCount + 1
hidden.SetFocus
cmdAddNew.Enabled = False
cmdMoveNext.Enabled = False
If frmNavigate.RecordsetClone.RecordCount > 0 Then
cmdMovePrevious.Enabled = True
Else
cmdMovePrevious.Enabled = False
End If
Else
lblTotalRecords.Caption = " of " & frmNavigate.RecordsetClone.RecordCount
hidden.SetFocus
cmdAddNew.Enabled = True
frmNavigate.RecordsetClone.Bookmark = frmNavigate.Bookmark
With frmNavigate.RecordsetClone
.MovePrevious
hidden.SetFocus
If .BOF Then
cmdMovePrevious.Enabled = False
Else
cmdMovePrevious.Enabled = True
End If
End With
frmNavigate.RecordsetClone.Bookmark = frmNavigate.Bookmark
With frmNavigate.RecordsetClone
.MoveNext
hidden.SetFocus
If .EOF Then
cmdMoveNext.Enabled = False
Else
cmdMoveNext.Enabled = True
End If
End With
End If
End Sub
1.bmp2.bmp
3.bmp
Not sure where you are using your code but just beware that you can't disable a control that has the focus. ie if your code is in the onClick event of your cmdMovePrevious command button then it won't work. You first have to move the focus to a different control before you can disable it.
ie
me.SomeotherControl.set focus
me.cmdMovePrevious.enabled = false.
As I said, I'm not sure here and I may be way of the mark, Just something to consider.
Leigh
ie
me.SomeotherControl.set focus
me.cmdMovePrevious.enabled
As I said, I'm not sure here and I may be way of the mark, Just something to consider.
Leigh
ASKER
SInjin: This isn't the issue. If you look at the images I posted the statement cmdMovePrevious.Enable = False is evaluated (it is highlighted while I am single stepping). So the .BOF condition is evaluating to true like it should, for some reason this statement doesn't have any effect on the enabled property.
Leigh: I posted below part of the code posted in my first post, I do set the focus to a hidden object on the form before attempting to set the enabled property on a button (I have previously run into the problem of focus before).
The only thing is I am just noticing I have On Error Resume Next at the beginning of my procedure and I never set it back to On Error Goto 0 after that. Does On Error Resume Next apply to the whole procedure then? If so, it may be surpressing an error at that statement. I am not back at work until tomorrow. Will have to try then.
Leigh: I posted below part of the code posted in my first post, I do set the focus to a hidden object on the form before attempting to set the enabled property on a button (I have previously run into the problem of focus before).
The only thing is I am just noticing I have On Error Resume Next at the beginning of my procedure and I never set it back to On Error Goto 0 after that. Does On Error Resume Next apply to the whole procedure then? If so, it may be surpressing an error at that statement. I am not back at work until tomorrow. Will have to try then.
hidden.SetFocus
cmdAddNew.Enabled = True
frmNavigate.RecordsetClone.Bookmark = frmNavigate.Bookmark
With frmNavigate.RecordsetClone
.MovePrevious
hidden.SetFocus
If .BOF Then
cmdMovePrevious.Enabled = False
Else
cmdMovePrevious.Enabled = True
End If
End With
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
luck,
-sinjin