Solved

Command button

Posted on 2000-04-07
3
160 Views
Last Modified: 2010-05-02
If I accidentally press any command buttons on a form two or three times, the calculated quantities should not change.  how can I do this?
0
Comment
Question by:fuad2
  • 2
3 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2693628
after the user clicks it once, disable the button until you want to allow the user to click it again.

command1.enabled = false
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2693638
or create a public boolean variable called answered or something and use it like this


Option Explicit
Dim answered as Boolean


Private Sub Form_Load()
answered = FALSE

Private Sub Command1_Click()
If answered = FALSE Then
   'do some calculations
   answered = TRUE
Else
   Exit Sub
End Sub
0
 
LVL 2

Accepted Solution

by:
ndnet earned 30 total points
ID: 2695392
I can see where this would be useful. The first answer given is better, since the user doesn't think that the button is still active.

If you use the second method, be sure to make edits to each textbox (or, more accurately, variable involved in the calculation) allow the command button to come back to life.

You could combine the two techniques  into your program like this:

Option Explicit
Dim answered as Boolean

Private Sub Textbox1_Change()
If answered = TRUE then
   'Allow calculations again
   answered = FALSE
   Command1.enabled = TRUE
End If

Private Sub Command1_Click()
If answered = FALSE Then
   'Insert happy calculations
   answered = TRUE
   Command1.enabled = FALSE
Else If answered = true then
Else
   msgbox "error"
End If
Exit Sub



You'll have to add the code from textbox1_change to all fields that change the data used by your calculations.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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