Solved

How to Disable a command button?

Posted on 2010-08-13
23
521 Views
Last Modified: 2013-11-28
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
0
Comment
Question by:cssc1
  • 9
  • 7
  • 6
  • +1
23 Comments
 
LVL 3

Expert Comment

by:jnbkze
ID: 33435321
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
 
LVL 10

Expert Comment

by:t_hungate
ID: 33435542
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
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33436016
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
 
LVL 10

Expert Comment

by:t_hungate
ID: 33436809
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
 

Author Comment

by:cssc1
ID: 33437690
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
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33437755
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
 

Author Comment

by:cssc1
ID: 33437855
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
 
LVL 10

Expert Comment

by:t_hungate
ID: 33437962
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
 
LVL 10

Accepted Solution

by:
t_hungate earned 500 total points
ID: 33437975
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
 

Author Comment

by:cssc1
ID: 33438391
t_hungate:
  Same problem, please see attached image.
Thanks,
CSSC1
SameProblem.jpg
0
 
LVL 10

Expert Comment

by:t_hungate
ID: 33438487
That is very odd, it works just fine on my end.

TLH
Your-form.jpg
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33438738
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
 

Author Comment

by:cssc1
ID: 33439072
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
 
LVL 10

Expert Comment

by:t_hungate
ID: 33439096
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
 
LVL 10

Expert Comment

by:t_hungate
ID: 33439106
This one is in MDB format, just in case you are using 2003.
Database11.mdb
0
 

Author Comment

by:cssc1
ID: 33439190
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
 
LVL 10

Assisted Solution

by:t_hungate
t_hungate earned 500 total points
ID: 33439297
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
 
LVL 10

Expert Comment

by:t_hungate
ID: 33439341
Let me know what you name your other question.  I may have found the issue.

TLH
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33440159
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
 

Author Comment

by:cssc1
ID: 33440890
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
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33440985
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
 

Author Comment

by:cssc1
ID: 33441504
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
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33441754
Then you have a problem, because it worked perfectly for me.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now