MS Access Forum / Forms Programming / March 2005
Coding a toolbar command button
|
|
Thread rating:  |
Rosemary - 10 Mar 2005 02:57 GMT Hello,
I have a toolbar button that opens a form that is used for notifications. I'd like to code this button so that, when there is a notification, the button's caption turns red.
Normally the notifications form is blank (no records). This is because, as soon as a notification expires, we delete it. We don't keep expired notifications in this database. Notifications are typed directly into the form, then the record is deleted when it expires.
Is there a way for me to create code that will allow the button caption to turn red when there is a notification? Where would I place it? At the form level? At the table level? Or would I attach a macro to the command button?
Many thanks,
Nikos Yannacopoulos - 10 Mar 2005 09:05 GMT Rosemary,
The code to change the caption code is simply:
Me.Command1.ForeColor = vbRed
within the form's own module, or
Forms!FormName.Command2.ForeColor = vbRed
in another module.
Now, how you capture the existence of a notification, is a different question, which cannot be answered specifically based on the info you provided. How are notifications created? For instance, if they are entered by users through a form, then the event to use would be some event on that form (which one specifically depends on how the form works). Alternatively, you could use a timer event to count the number of records in the table where notifications are stored. In the case of entry through a form, I would prefer an unbound form with a Save command button which stores the notification and changes the caption color at the same time.
HTH, Nikos
> Hello, > [quoted text clipped - 12 lines] > > Many thanks, Rob Parker - 10 Mar 2005 12:20 GMT Hi Nikos (and Rosemary),
I was going to respond along the lines of your post, but then noticed that Rosemary asked about changing the caption of a TOOLBAR button, not a button on a form. I'm not even sure if that can be done (well, anything can be done with lots of devious API tweaking, but ...).
If the button is on a form, then the "trigger" could come via a dcount on the table containing notifications (if that's how they're stored), with the code being place in the form's load event. For example:
If dcount("*","tblNotifications") then Me.Command1.ForeColor = vbRed else Me.Command1.ForeColor = vbBlack End If
The choice of event to place the code in depends, as you said, on many things.
HTH,
Rob
> Rosemary, > [quoted text clipped - 38 lines] > > > > Many thanks, Nikos Yannacopoulos - 10 Mar 2005 13:23 GMT Rob,
You're right, I missed this detail!
Thanks, Nikos
> Hi Nikos (and Rosemary), > [quoted text clipped - 79 lines] > >>>Many thanks, Rosemary - 10 Mar 2005 14:01 GMT Hi Nikos,
The dCount method worked. I placed a command button on my Switchboard next to the Notifications menu item. I then placed your code in the OnLoad event of the Switchboard. If there is a record in tblNotifications, it changes color. If not, it stays black. Thanks!
Now, I need to have the code fire whenever the Switchboard is accessed, in addition to when it loads. Do I use a Refresh? Should I put it in the OnOpen event?
Thanks again, Rosemary
> Hi Nikos (and Rosemary), > [quoted text clipped - 68 lines] > > > > > > Many thanks, Rosemary - 10 Mar 2005 13:33 GMT Hi Nikos and Rob,
Thank you both for your replies. The button is currently on the toolbar, however, after reading your post, I am thinking I should use a button on a form instead. Can I place a button on the Switchboard and use the code you have supplied? This way, whenever anyone goes to the Switchboard, they can see if they need to check notifications.
Many thanks, Rosemary
> Rosemary, > [quoted text clipped - 38 lines] > > > > Many thanks, Rosemary - 10 Mar 2005 13:39 GMT Hi Nikos,
In response to your question about how we capture notifications:
I have created a simple form with four fields date, name, expiration date, and notification details. The form is based on a table, which is not related to any other table in the database.
The user enters the information by simply typing it in.
When the expiration date is reached, a user simply clicks the "delete record" button I created, and that notification is deleted from the database.
Does this supply the information you need? The key field is called ReservID. I was thinking of creating a query and using the criteria that the ReservID is not "0" (I'm new to this). Does this sound possible? If not, which event do you t hink we would use?
Many thanks, Rosemary
> Rosemary, > [quoted text clipped - 38 lines] > > > > Many thanks, Nikos Yannacopoulos - 10 Mar 2005 14:29 GMT Rosemary,
In light of this new information, I would put the following procedure in a general module:
Sub Check_For_Notifications() vCount = DCount("*", "tblNotifications") If vCount = 0 Then Forms!FormName.Command2.ForeColor = vbBlack Else Forms!FormName.Command2.ForeColor = vbRed End If End Sub
And call it from the following events:
Switchboard: Open Notif. Entry Form: Current, Close Delete Record button: Click
simply with a line of code like:
Check_For_Notifications
I believe this will capture all events, and so keep it uptodate at all times.
If you wish, you can make a simple delete query on your tblNotifications where expiry < Date, and run it in the Open event of the switchboard, so it will clean up expired notifications automatically every time the database is opened. In that case, the call to the sub in the switchboard's Open event should be after the delete query is run.
HTH, Nikos
> Hi Nikos, > [quoted text clipped - 59 lines] >>> >>>Many thanks, Rosemary - 11 Mar 2005 03:35 GMT Hi Nikos,
This worked perfectly. Thanks so much!
Rosemary
> Rosemary, > [quoted text clipped - 95 lines] > >>> > >>>Many thanks, Nikos Yannacopoulos - 11 Mar 2005 08:24 GMT Glad to help.
Nikos
> Hi Nikos, > [quoted text clipped - 101 lines] >>>>> >>>>>Many thanks,
|
|
|