Solved

Command button

Posted on 2000-04-07
3
157 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now