Turn button red after clicked

lotarugg

Registered User.
Local time
Today, 08:52
Joined
Mar 15, 2011
Messages
34
Hi,

I have a button that when clicked sends emails to people who have had records added to the database that day for their attention. I don't want people to click it twice so I need some alert that tells people that the button has been click ie it turns red for the remainder of the day?

Thanks
 
I'm guessing you didn't make this, did you?

Something as simple as
Code:
Me.YourButtonName.BackColor=vbRed
should work. Place it in the onClick event.
 
Yes I made it, has taken me about a year though of finding my way and doing bits now and then.

How to make this code once run persistent for whoever opens the database for a day and expire from midnight? I think is going to be tricky.

Thanks for help
 
i didn't think you could change a button backcolor? is that A2010 or something?

Anyway - you need to save the setting somewhere, and test it when the form opens. Maybe use a field in a "settings" table. Store the last date processed.

you need some code in the button click event anyway. what if they click it, even if it is red?
 
You perhaps need to Store a value like the date per record and

If this SentDate is not today set the SentDate to null and perhaps enable the button otherwise
if SentDate is today's date change the Button colour to Red and even disable it.

Simon
 
Thinking about if again perhaps it would be better to leave the SendDate as is because this way you know the last time somethiing was sent and just update it on send.

Simon
 
i didn't think you could change a button backcolor?

Wow, look at that, you cant! I'm sure something like it can be done though. I have seen a demo that changed a button on hover. So I'm sure something can be done.
 
Have this now which calls the SendEmail function if the Email_date field does not contain todays date. Only problem is "result = Email_date = Now()" does not populate the field with todays date. Any help would be great. Thanks

-----------------------------------------
Function EmailSent()
If Email_date <> Now() Then
result = Email_date = Now()
result = SendEMail()

Else

result = "Today's emails have already been sent!"

End If

End Function

------------------------------------------
 
Change it to Me.email_date=Now

Also, why do you bother testing if the email <> now? This will ALWAYS be true, because now includes time. Maybe you want to be using date(), or should rethink this approach.

edit- To clarify, the email date will always be some date in the past, right? You are asking if that date IN THE PAST is anything other then now(), where now is the date and time at this exact moment. This will always be true.
 
Ah ok thanks,yes I want today's date without the time. But when I use
result = Me.Email_date = Date I get invalid use of Me key word.
 
So your function is stored in a module? And your calling it from a form? If so, then that error makes sense, right? Me is not relevant from the point of view of a module. What you need to do is pass the value to the module from the calling statement.

Use this in the function.
Code:
Function Email_Sent(dteDate as date)

The calling statement can use this:
Code:
call Email_Sent(me.Email_Date)

So what is going on here is that when the function is called, the function requires input, a date value to be specific. When you call it, the format is YourFunctionName(SomeParameterHere).

Another thing you should consider is the difference between subs and functions. Subs carry out orders. Functions carry out orders, and return a value. If no value is returned, then you should be using a sub. In your code, EmailSent does not equal anything. As it stands, it should be a sub. You could change that if you wish. Perhaps you want the returned value to tell you whether the function ran correctly. In this case, you only need a boolean (true/false).

Code:
Public Function SentEmail(dteDate as date) as Boolean
    'your code here
    SentEmail=true
End Function

Now in your code, you can say If SentEmail(Some Date) =true then ...

The function will run, and it will return true or false.
 
Firstly thanks for all your help with this. You’re right that I need no output. I didn’t know the difference between functions and subs. A sub will do me fine though I’m struggling with the syntax you have provided. All I need is to make this work and it’s doing everything I need at the moment except populating the Email_Date field in a table called Table_Date with today’s date. In short, how do I tell the sub below to use the field Email_Date in the table Table_Date?



Sub EmailSent()
If Email_date <> Date Then
Result = [Tables!Table_Date.Table.Email_date] = Date
Result = SendEMail()

Else

Result = "Today's emails have already been sent!"

End If

End Sub
 
Sub EmailSent()
If Email_date <> Date Then
Result = [Tables!Table_Date.Table.Email_date] = Date
Result = SendEMail()

Else

Result = "Today's emails have already been sent!"

End If

End Sub

Your saying that Result=Some Value = Some Value. Does that make senses? No!

First of alll, what is result? You did not say. Second of all, you have two equals sings! That does not make senses? No! Think of code like algebra I, nice and simple.
 
Ok :) I get what you're saying but I'm still in the dark about defining the feild. The below gives 'object required' error when I try to define Email_Date on the second line.

Sub EmailSent()
If Tables!Table_Date.Table.Email_Date <> Date Then
Tables!Table_Date.Table.Email_Date = Date
Result = SendEMail()

Else

Result = "Today's emails have already been sent!"

End If

End Sub
 
Code:
Sub EmailSent()
If Me.Email_Date <> Date Then
me.Email_Date = Date

else

msgbox("Today's emails have already been sent!")

End If


Move this into your form. Notice I got rid of result, because you did not say what result is.
 

Users who are viewing this thread

Back
Top Bottom