473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Restrict a toggle button to a single click

I am constructing a database to process product returns for my Company.
I have a number of toggle buttons to identify the stage to which each
return has been processed. For example, clicking the first button
confirms that the goods are now in our building awaiting initial
processing. This button then fires off an email to our warehouse staff
alerting them to the fact. I want to restrict these buttons to single
use, so that once the email has been sent and the return confirmed, it
cannot then be clicked again potentially triggering an email each time
it is clicked. Other buttons on the form also print appropriate reports
to appropriate printers, in the interest of the rain forests, I want to
restrict these buttons so that once clicked, they cannot be clicked
again. I'd appreciate some guidance, in other words, please help!!

Nov 13 '05 #1
4 4318
Me.MyToggle.Enabled = False after the toggle has been used.

When opening the form, if your underlying field has a value, disblable
the toggle as above.

Nov 13 '05 #2
Thanks for your help.
I don't want to appear dim, but the code you suggested doesn't appear to
be valid. Using the form's OnOpen command with the code you suggest has
the effect of preventing the form from opening at all. Can you help with
any coding that would enable the OnOpen command to identify whether the
toggle had previously been pressed, and therefore whether to enable it
or not?

Thanks again

Neil

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3

"Neil Coleclough" <no****@devdex.com> wrote in message
news:25************@news.uswest.net...
Thanks for your help.
I don't want to appear dim, but the code you suggested doesn't appear to
be valid. Using the form's OnOpen command with the code you suggest has
the effect of preventing the form from opening at all. Can you help with
any coding that would enable the OnOpen command to identify whether the
toggle had previously been pressed, and therefore whether to enable it
or not?

Thanks again

Neil


The following sub does the updating for all toggle buttons on your form (if
this is not appropriate you can list them explicitly). If you are disabling
a control then you need to make sure it does not have the focus at that
time.
I would call this code from the form's Current event and after you have
updated the controls, so for three toggles the code might look like this:

Private Sub UpdateToggles()

On Error GoTo Err_Handler

Dim ctl As Control
Dim blnError As Boolean

For Each ctl In Me.Controls
With ctl
If .ControlType = acToggleButton Then
.Enabled = Not Nz(.Value, 0)
End If
End With
Next ctl

Exit_Handler:
Exit Sub

Err_Handler:
' If we are attempting to disable the control while it
' still has focus, then move the focus elsewhere and re-try
If (Err.Number = 2164) And (blnError = False) Then
blnError = True
Me.txtSomeOtherTextbox.SetFocus
Resume
Else
MsgBox Err.Description, vbExclamation, "Error: " & Err.Number
Resume Exit_Handler
End If

End Sub

Private Sub Form_Current()
UpdateToggles
End Sub

Private Sub tglOne_AfterUpdate()
UpdateToggles
End Sub

Private Sub tglTwo_AfterUpdate()
UpdateToggles
End Sub

Private Sub tglThree_AfterUpdate()
UpdateToggles
End Sub
Nov 13 '05 #4
Neil Coleclough wrote:
I want to restrict these buttons to single
use, so that once the email has been sent and the return confirmed, it
cannot then be clicked again potentially triggering an email each time
it is clicked. Other buttons on the form also print appropriate reports
to appropriate printers, in the interest of the rain forests, I want to
restrict these buttons so that once clicked, they cannot be clicked
again. I'd appreciate some guidance, in other words, please help!!


What brian and the other respondent have explained are all good, but the
important underlying thing is this:

You MUST have, somewhere in your data tables, a field which indicates,
for each record, whether or not the email has been sent, which report
have been printed.

So in your data structure, to which you don't provide any insight, you
might have something likt this:

TBL_REPORTS

REP_PK Primary key, autonumber
REP_NAME text, short name of a report
REP_DESCRIPTION text, comments, etc, if any on a report
REP_EMAIL_SENT date/time, initial value is null, populate with current
date/time when a report is emailed
REP_PRINTED as per REP_EMAIL_SENT, above.

Another (preferred, in my opinion) option would be to have a separate
table which indicates all instances of emailling and report printing
with a foreign key pointing to the report table.

I would not have the toggle button disabled. You will severely tick off
users who don't care about Treebeard's friends if they can't run reports
when they want.

What I would do instead is simply have something like the following as
an afterupdate event fo each individual toggle button as appropriate.
This is air code and assumes the displayed form is bound to an
underlying SQL statement or query with access to the date/time fields
for when report was sent/last sent. It also assumes the toggle button
is selected and then another button elsewhere prints reports based on
the toggles selected:

sub tglSelReport_afterupdate()

'response required if the toggle is turned on (value = -1) and
'the date last printed is populated.

if me.tglSelReport = -1 and isnull(me.REP_PRINTED) = False then

'This report has been printed on the date indicated by the
'field. Inform user and ask if they want to continue.

if msgbox("This report has been printed before on " & _
format(me.REP_PRINTED, "d mmm yyyy") & _
"If you want to avoid a Saruman type fate, it's " & _
"recommended that you press cancel and look around " & _
"for the report." & vbcrlf & vbcrlf & _
"Continue?", vbQuestion + vbOkCancel, _
"Already Printed!") = vbCancel then

'If action cancelled, turn off toggle button

me.tglSelReport = 0

End If

End if

end sub
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jürgen Heyn | last post by:
Good morning, on form 2 input elements and 1 image are placed. The 1st (Index) one is "hidden", the 2nd ) is an empty textbox. When clicking the picture I would like to toogle a boolean value....
0
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, which has 3 toggle buttons (1 of which is tglName, which I will be using to demonstrate my problem). The buttons are used to sort the form (explanations...
5
by: Steven | last post by:
Can anyone tell me how to toggle the "Caps Lock" key? Thanks in advance
1
by: kimmie | last post by:
I am using buttons on a toolbar and I want to use the buttons as toggles. When I click the button the first time I want my picture box to display by setting the picture box to visible. But I need...
1
by: John | last post by:
Hi How can I make some of the buttons on BindingNavigator toggle i.e. when one button is clicked others unclick automatically? Thanks Regards
2
by: Mel | last post by:
Hi, is there any way I can implement toolstrip toggle button simular to the MS Word alignment button? if one toggle button already pressed down, if user click on the "pushed down button", the...
2
by: John Smith | last post by:
How can I use a transparent command button to change a checkbox? I have my records set up in a continuous form and I want theuser to be able to click on the record and have this toggle the...
1
by: Jeffrey Christiansen | last post by:
I wanted to add a toggle button to a VB2005 form to be used for a simple Windows Application (i.e. compiled to a "*.exe"), so I added the ActiveX Microsoft Forms Object toggle button, however I...
7
n8kindt
by: n8kindt | last post by:
i have a continuous form that i want a toggle button to display "on" or "off." everything i try changes every single caption on the continuous form--rather than the single row. here's what i have so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.