How to Disable a command button?

PROBLEM
I am trying to Disable Command8 until the user clicks (Selects) an AHA on the form “frmAHA_Selection_Form_VER1”.

See image and DB
Disable.jpg
EE-TEST-8-3-2010-AHA-Builder-201.zip
cssc1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jnbkzeCommented:
I do recall in VB there is a toolbar where you can select the command button and say visible= false

I recall the same for delphi, but I have no idea what program you are using.. so maybe a command like commandbutton1.visible=false?
0
Tony HungateDirector of TrainingCommented:
I think that I took care of the issue.  Have a look at your form and make sure that it is doing what you requested.

Good looking app by the way, nicely designed form.

TLH
EE-TEST-8-3-2010-AHA-Builder-201.zip
0
Dale FyeCommented:
In the forms load event, set the enabled property of the command button to false.

Then, I would put a hidden textbox in the forms footer with a control Source like: = Sum([Selected]).  You will need to change that field name as appropriate for your checkbox

Then, In the AfterUpdate event of your Select checkbox, do something like:

me.cmdNext.Enabled = (me.txtSumSelected <> 0)
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Tony HungateDirector of TrainingCommented:
I trired that approch, problem was there is a a sub that loops through to ensure that the user can only have one record selected at a time. If you use a Sum, it will negate the single record selecte function.
0
cssc1Author Commented:
t_hungate:
   I trid the db and the NEXT button is disabled, however, even when the user selects an AHA it stays disabled. After the user selects an AHA the NEXT button should become activated.
0
Dale FyeCommented:
A couple of points.

1.  you really should use a naming convention for your controls.  When someone other than you looks at this forms code module, they have to figure out what command8, command10, and command66 and command67 are all about.  Wouldn't it make more sense to label this cmdNext, cmdClose, cmdPrevious

2.  As I mentioned in my previous post, I would set set command8's Enabled property to False.  You can do that in design view, but if you inadvertantly save the form with it enabled, it will retain the enabled status.  Instead, use the form_Load event to set the property to False.

3.  I've added just a few lines to your code for the Select_Click event.  See the code below.  Basically, I added a check to see whether the value of Select = True.  If so, then reset the other values and enable Command8.  If False, then don't worry the other values of Select, but you do need to disable Command8.
Private Sub select_click()

Dim lngID As Long

    If Not Me.NewRecord Then
        'added this test
        If Me.Select = True Then
            lngID = Me.AHAID
            
            With Me.Recordset
                  .MoveFirst
                 Do Until .EOF
                    
                    If Me.AHAID <> lngID Then
                      .Edit
                      ![Select] = 0
                      .Update
                    End If
                      .MoveNext
                 Loop
                 .FindFirst "[AHAID]=" & lngID
            End With
            'added next 3 line
            Me.Command8.Enabled = True
        Else
            Me.Command8.Enabled = False
        End If
    Else
        'MsgBox "New  record"
    End If

End Sub

Open in new window

0
cssc1Author Commented:
fyed:
  I must be doing something incorrect. Where do I put the code you wrote?

Here is the code I currently have for the on click event for command8:
Private Sub Command8_Click()
On Error GoTo Err_Command8_Click

    Dim stDocName As String

    stDocName = "Macro_Close_AHASelect_Open_frmAHA_VER1"
    DoCmd.RunMacro stDocName

Exit_Command8_Click:
    Exit Sub

Err_Command8_Click:
    MsgBox Err.Description
    Resume Exit_Command8_Click
   
End Sub
False-8-14-2010.jpg
0
Tony HungateDirector of TrainingCommented:
cssc1

It is working perfectly for me.  When you open the form the Next> button is disabled.  Upon AHA record selection the button is enabled. If you switch between records it will remain enabled.  If you select a record, and then de-select it, it will go back to a disabled state. I am pasting the entire forms code here, check it against the one you are using and see if it matches.

TLH
Option Compare Database

Private Sub Check63_Click()
'Me.Check63 = ""
End Sub

Private Sub Command8_Click()
On Error GoTo Err_Command8_Click

    Dim stDocName As String

    stDocName = "Macro_Close_AHASelect_Open_frmAHA_VER1"
    DoCmd.RunMacro stDocName

Exit_Command8_Click:
    Exit Sub

Err_Command8_Click:
    MsgBox Err.Description
    Resume Exit_Command8_Click
    
End Sub
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

    Dim stDocName As String

    stDocName = "Macro_Close_AHA_Selection_Open_Splash"
    DoCmd.RunMacro stDocName

Exit_Command10_Click:
    Exit Sub

Err_Command10_Click:
    MsgBox Err.Description
    Resume Exit_Command10_Click
    
End Sub

Private Sub Frame48_DblClick(Cancel As Integer)
'Me.Frame48 = ""
End Sub
Private Sub Combo57_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[AHAID] = " & Str(Nz(Me![Combo57], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Private Sub Command65_Click()
On Error GoTo Err_Command65_Click

    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_Command65_Click:
    Exit Sub

Err_Command65_Click:
    MsgBox Err.Description
    Resume Exit_Command65_Click
    
End Sub

Private Sub Form_Open(Cancel As Integer)

CurrentDb.Execute "update [3-tblAHA_VER1] set [select]=0"
'Me.Command8.Enabled = False
End Sub

Private Sub Select_AfterUpdate()
If Me.Select.Value = -1 Then Me.Command8.Enabled = True
If Me.Select.Value = 0 Then Me.Command8.Enabled = False
DoCmd.RefreshRecord
End Sub

Private Sub select_click()

Dim lngID As Long

If Not Me.NewRecord Then
lngID = Me.AHAID

With Me.Recordset
      .MoveFirst
     Do Until .EOF
        
        If Me.AHAID <> lngID Then
          .Edit
          ![Select] = 0
          .Update
        End If
          .MoveNext
    Loop
     .FindFirst "[AHAID]=" & lngID
End With
Else
    'MsgBox "New  record"
End If


End Sub

Private Sub Command66_Click()
On Error GoTo Err_Command66_Click


    DoCmd.GoToRecord , , acPrevious

Exit_Command66_Click:
    Exit Sub

Err_Command66_Click:
    MsgBox Err.Description
    Resume Exit_Command66_Click
    
End Sub
Private Sub Command67_Click()
On Error GoTo Err_Command67_Click

    DoCmd.GoToRecord , , acNext

Exit_Command67_Click:
    Exit Sub

Err_Command67_Click:
    MsgBox Err.Description
    Resume Exit_Command67_Click
    
End Sub

Open in new window

0
Tony HungateDirector of TrainingCommented:
I have put the code on both the ver1 form and the old one in the copy of the DB.

Let me know if it still does not work for you.

TLH
EE-TEST-8-3-2010-AHA-Builder-201.accdb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cssc1Author Commented:
t_hungate:
  Same problem, please see attached image.
Thanks,
CSSC1
SameProblem.jpg
0
Tony HungateDirector of TrainingCommented:
That is very odd, it works just fine on my end.

TLH
Your-form.jpg
0
Dale FyeCommented:
You got the idea correct about disabling the NEXT button as the default.  The other code replaces the code you currently have for the SELECT_CLICK event.  
0
cssc1Author Commented:
fyed:\
  Sorry, i don't understand your explaination. What do you mean by:
The other code replaces the code you currently have for the SELECT_CLICK event?
0
Tony HungateDirector of TrainingCommented:
I am really baffled by this.  What version of Access are you running?  This thing is working perfectly on my end.

I am attaching a new db that I only copied the needed tbl, from, macro and modules.

Let me know if this one works for you.  It is rock solid on my end.

TLH
Database1.accdb
0
Tony HungateDirector of TrainingCommented:
This one is in MDB format, just in case you are using 2003.
Database11.mdb
0
cssc1Author Commented:
t_hungate:
  Please see new ERROR message in image when I click the for:
frmAHA_VER1.


NewError-8-14-2010.png
EE-TEST-8-3-2010-AHA-Builder-201.zip
0
Tony HungateDirector of TrainingCommented:
I am sorry but, I never checked that out before.  I am not sure what is causing that one.  In the new db you sent the title does not seem to be caring over to the next form.  The custom error message you have provided seems to fire no matter what you do, almost like it is validating if a new recored has been created.

If you would like me to look into that a bit deep, I would be happy to.  However, if you are satisfied with the solution for your form can you please, assign the points for this question and open a new one, for your pop up error.

I just looked at the first version of the db that you sent me and that error is already present.

Sorry to have to do it this way, but EE does not like two part questions.

TLH

I will start looking into it now, that way if you open another question, we can get it taken care of quickly.
0
Tony HungateDirector of TrainingCommented:
Let me know what you name your other question.  I may have found the issue.

TLH
0
Dale FyeCommented:
css1,

I'm not sure what you are unclear about, but am sending you that form, with my edits back in a new accdb.  Copy this form into your application and see if it meets your needs.
AHA-BuilderSampleForm.accdb
0
cssc1Author Commented:
fyed:
   Same problem. I attached the DB with the SampleForm so you can see what it is doing.
8-14-2010-AHA-Builder-2010-.zip
0
Dale FyeCommented:
If you are talking about the same problem that you mention to t_hungate about the popup form after clicking Next, I would agree.  We have both provided you solutions to your original stated problem.  Assign point, then post another question.  

However, since we are unable to review all of your code, I would ask that you only provide those forms, tables, and queries that are pertinent to the problem.  Personally, I have real trepidation about downloading someone elses code and running it on my computer unless I can review ALL of the code before opening a form in Form view and allowing the code to run freely.
0
cssc1Author Commented:
fyed:
Sorry, I should of explained better. By the same problem I mean the same as in post:

08/14/10 04:54 PM, ID: 33438391
0
Dale FyeCommented:
Then you have a problem, because it worked perfectly for me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.