Command Button Question

M

Mr-Re Man

Is it possible that when a user clicks a command button on a form it can do
one of the following:

1. The buttons texts changes to 'Accepted' to show it has been pressed then
reverts back to its original text.

or

2. The button text changes colour for a 2 second period before become active
again.

The reason for this is that I have a form that Klatuu has been helping me
with, but when users click the form I don't want users to think that they
haven't clicked a button and do it again and therfore create another record
in the table, thus distorting the figures.

thanks in advance
 
D

Douglas J. Steele

1. Private Sub MyButton_Click()
Dim strOldCaption As String

strOldCaption = Me.MyButton.Caption
Me.MyButton.Caption = "Accepted'

' the rest of your code...

Me.MyButton.Caption = strOldCaption

End Sub

2. Private Sub MyButton_Click()

Me.MyButton.Forecolor = vbRed
Me.TimerInterval = 2000

' The rest of your code...

End Sub

Private Sub Form_Timer()

Me.MyButton.ForeColor = -2147483630
Me.TimerInterval = 0

End Sub

(-2147483630 was the value of my button's ForeColor property originally. Use
a different value if appropriate)
 
M

Mr-Re Man

These would be brilliant, but I think they maybe conflicting with my button
code.
For No.1 I have merged it with this code, but it doesn't seem to change to
Accepted.

Private Sub Command4_Click()

Dim strOldCaption As String

strOldCaption = Me.Command4.Caption
Me.Command4.Caption = "Accepted"

Call AddVisitor("Residents Parking", "EC")

Me.Command4.Caption = strOldCaption

End Sub

The second one does turn the text red but interferes with the clock I have
set-up as that also uses the timer function. The timer interval on the form
is set to 1000 plus the code below is repeated in On_Open.

Private Sub Form_Timer()
On Error GoTo Form_Timer_Error

Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm:ss AMPM")

Form_Timer_Error:
If Err.Number <> 0 Then
MsgBox "MS Access has generated the following error" & vbCrLf &
vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: Form_frmClock Demonstration /
Form_Timer" & vbCrLf & _
"Error Description: " & Err.Description, vbCritical, "An Error has
Occured!"
End If
Exit Sub

End Sub

Hope this can be sorted as these examples are the business!

-----------------------------------------------------------------------------
 
M

Mr-Re Man

Ah, I see, would it be at all possible to wait for a timer to expire before
using the Call action or doesn't it work like that?
 
D

Douglas J. Steele

If you look at the second solution I gave (the one that changed the text
colour, then changed it back 2 seconds later), you'll see that I set the
form's TimerInterval (to 2000 in that case, which corresponds to 2 seconds),
andd put code in the form's Timer event which did something and then set the
TimerInterval back to 0.

If that's all you'll be using the timer for, you could put the call to
AddVisitor in that event, so that it waits 2 seconds before firing.

Another alternative would be to use the Sleep API. There's an example at
http://www.mvps.org/access/api/api0021.htm on "The Access Web"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top