By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Restrict a toggle button to a single click

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.