Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set control .enabled property to false, control .enabled property still true

Posted on 2008-11-02
4
Medium Priority
?
545 Views
Last Modified: 2012-05-05
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.
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

Open in new window

1.bmp
2.bmp
3.bmp
0
Comment
Question by:bejhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:sinjin
ID: 22864058
The root cause of this seems to be that even though you be on the first record, it is still after BOF.  In other words, Recordsets have start with BOF, then move into Record 1, 2,3, ... X, new record, and finally EOF.  In your sample code you move previous only one time.  Perhaps if you used your recordset clone to test if a second move previous = BOF then your code would work as you expect.  Alternatively, you could check the index value of the current record. If it = 1 then you know you are on the first record and you could then disable the move previous button.
luck,
-sinjin
0
 
LVL 14

Expert Comment

by:ldunscombe
ID: 22865041
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
0
 
LVL 1

Author Comment

by:bejhan
ID: 22871513
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.
        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

Open in new window

0
 
LVL 14

Accepted Solution

by:
ldunscombe earned 1000 total points
ID: 22891911
If by "Hidden Object" you mean that it's visible property is set to false then that is probably the error you are missing.

ie You can't set the focus to a hidden control.

Leigh
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question