?
Solved

Command button

Posted on 2000-04-07
3
Medium Priority
?
164 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
[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
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 90 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 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