Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 5th, 2007, 07:15 PM
Registered User
Join Date: Aug 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing Command buttons on a form

In my working environmnet, I have a number of command buttons (click events) that are used to process sample we use in our call center. In some cases we have multiple steps that have to be done in order to process the sample (i.e. consumers demographic info, etc)

Sometimes, the end users forget to push a button and it causes things to happen out of sequence which (at times) causes me a real headache.

So, this is what I would like to do. For arguments sake, lets say I have a form with five command buttons not including the "Close Form" button.

1. When the form is opened, the first command button would be active and the remaining four would be inactive.

2. After the first button was pressed and the process completed, the 2nd button would become active. The 1st button would be inactive and so on. Thus allowing the user to only select one button at a time.

If the user selects the close form, and all of the buttons have not been pressed (indicating all steps have been completed) they would get a warning message telling them that they haven't completed the following;steps......blah, blah, etc.

Or whatever wasn't selected during the various click events for that form.



Reply With Quote
  #2 (permalink)  
Old September 6th, 2007, 06:56 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

There are a couple of ways to do this. I would put a text box on the form, hide it, and then when the first button was clicked, add a 1 to the text box. Then when the second was clicked, change it to 2, etc. When the close form button is clicked, have it check the value in the hidden check box and if it does not = 5, have it pop up a message box, and then Exit Sub, else, do whatever it is supposed to do.

The problem with the other issue of making the buttons inactive based on their own click event is that they can't be set to inactive while they have focus. SO...

When each button is clicked, add this code (pretend you have a field on the form that should have focus first called Me.PKID):


Then, on the On Got Focus event of the PKID field, add this code:

Me.Button1.Enabled = False

However, you are going to need to do flow control to have the On Got Focus event Also check the hidden text field. So, for the On Current event of the form, I would put this code:

Me.HiddenTextField = 0

That sets the text field to 0 since no buttons have been clicked yet.

Then on the On Got Focus Event of the PKID, or whatever field gets focus first on the form, add this code:

Dim iButton As Integer

iButton = Me.HiddenTextField

Me.Button1.Enabled = False
Me.Button2.Enabled = False
Me.Button3.Enabled = False
Me.Button4.Enabled = False
Me.Button5.Enabled = False

Select Case iButton
   Case 0
     Me.Button1.Enabled = True
   Case 1
     Me.Button2.Enabled = True
   Case 2
     Me.Button3.Enabled = True
   Case 3
     Me.Button4.Enabled = True
   Case 4
     Me.Button5.Enabled = True
End Select

This will set all the buttons to disabled, and then enable the one that should then be enabled. If no button has been clicked yet, then first button will be enabled and all the others disabled. If the first one has been clicked, the second one will be enabled and all the others disabled, etc.

Did that help any?

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
datagrid command buttons CyberW ASP.NET 3.5 Basics 21 November 29th, 2008 04:02 PM
Using command buttons in Access kelljw BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 July 4th, 2006 07:21 AM
Labels as command buttons RichMW Access VBA 0 February 18th, 2005 09:10 AM
Graphics For Command Buttons Teqlump Access 1 November 24th, 2004 11:02 AM
Datagrid command buttons badgolfer ASP.NET 1.0 and 1.1 Basics 22 July 27th, 2004 02:42 AM

All times are GMT -4. The time now is 01:55 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.