Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to create a but so that on the third consecutive time it is
touched that it will send out an email. i was wondering if anyone has any
ideas, any help would be appreciated.

Thank You,

Donbenz
 
I am trying to create a but so that on the third consecutive time it is
touched that it will send out an email. i was wondering if anyone has any
ideas, any help would be appreciated.

Thank You,

Donbenz

Why in the world .... ?

Code the command button click event:

Static intX as integer
intX = intX + 1
If intX = 3 Then
DoCmd.SendObject .... read VBA Help for the necessary arguments ...
intX = 0
End If
 
Over what period of time? Seconds, hours, days?

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
 
It could up to as long as days becuase it is tracking shipping, is there
anyway to have it reset when the name in a certain field changes.
 
Well, assuming it's possible for the user to shutdown the database between
button presses, I'd recommend storing the button press count in a table.

Private Sub myButton_Click()
Dim db As Database
Dim rs As DAO.Recordset
Dim strSQL As String

Set db = CurrentDb

strSQL = "SELECT ButtonClickCount FROM tblButtonClicks " & _
"WHERE SomeIdentifier = " & someotheridentifier

Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If rs.AbsolutePosition > -1 Then
If rs!ButtonClickCount = 2 Then
'do whatever you want
rs.Delete
Else
rs.Edit
rs!ButtonClickCount = rs!ButtonClickCount + 1
rs.Update
End If
Else
rs.AddNew
rs!ButtonClickCount = 1
rs!someidentifier = someotheridentifier
rs.Update
End If

rs.Close
Set rs = Nothing
Set db = Nothing
End Sub

If you want the count to reset when a certain value is entered into, say, a
textbox, then maybe something like this:

Private Sub txtTextBox_AfterUpdate()
Dim strSQL As String

If Me!txtTextBox = "somevalue" Then
strSQL = "DELETE * FROM tblButtonClicks " & _
"WHERE SomeIdentifier = " & someotheridentifier

On Error Resume Next
CurrentDb.Execute strSQL, dbFailOnError
If (Err <> 0) Then
MsgBox "Couldn't reset button click count"
End If
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
I am unfimiliar with vba and am having trouble entering the data to get the
code to work if you could help me out by letting me know how to set the rs
and other things like that i would appreciate it
 
Don,

1. Since I don't know what the button is for, I have to make an assumption
for the sake of providing an answer. If the button is for, let's say,
activities, you should create a new table called, let's say,
tblButtonClicks. Give it the following fields:
ButtonClickID (Autonumber - Primary Key)
ButtonClickCount (Integer)

2. Assuming your button is called myButton, do the following:
a) Open the form in design view.
b) From the View menu, select Properties. The Properties dialog is
displayed.
c) Click the button.
d) Select the Event tab on the Properties dialog.
e) Click in the textbox for On Click. You'll notice two buttons appear
on the right-hand-side.
f) Click the rightmost button.
g) If the Choose Builder dialog displayed, click Code Builder, then
click OK. You'll notice the procedure stub has been created for you.
h) Add the following between Private Sub... and End Sub.
Dim db As Database
Dim rs As DAO.Recordset
Dim strSQL As String

Set db = CurrentDb

strSQL = "SELECT ButtonClickCount FROM tblButtonClicks " & _
"WHERE SomeIdentifier = " & someotheridentifier

Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If rs.AbsolutePosition > -1 Then
If rs!ButtonClickCount = 2 Then
'do whatever you want
rs.Delete
Else
rs.Edit
rs!ButtonClickCount = rs!ButtonClickCount + 1
rs.Update
End If
Else
rs.AddNew
rs!ButtonClickCount = 1
rs!someidentifier = someotheridentifier
rs.Update
End If

rs.Close
Set rs = Nothing
Set db = Nothing

i) Close the code screen.
j) Save the form.

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------
 
Don,

Slight typo (based on another idea I had).

"If the button is for, let's say, activities, ..." should read "If the
button is for button clicks..."

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------
 
Don,

Looks like I have a blind spot (directly in front of my nose). Just scratch
the whole of Step 1, and replace it with "Create a new table called
"tblButtonClicks. Give it the following fields:"

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------
 
Back
Top