Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Current Event?

Status
Not open for further replies.

kristi1023

Programmer
Jan 8, 2002
59
US
Hello All,

I have code on the current event that is color coding a label on a form. The code only works when I switch from design view to form view. I tried adding me.visible=true to the on activate event with no success.

Any suggestions are greatly appreciated.

Thank you,
Kristi
 
Under what circumstances do you want the label to change color?

When everything is coming your way, you're in the wrong lane.
 
Genomon,

I want the label to be color coded on the open event only. I have tried moving the code around to different events, like on open, on current, on activate, but the only time it works properly is when the code is in the on current event and when I switch from design to form view.

Thank you,
Kristi
 
Hey Kristi,

Just a thought, but what about if you put the color code in the "on current" or maybe the "on got focus" event, then switch the tab order so that control is on the top? So when that form opens, it's selected?

It's kind of low tech, but it might work.
 
OK let's say you want it to be yellow when the form opens. Set its backcolor property to yellow as its default. When do you want the color to change to whatever "normal" is?

When everything is coming your way, you're in the wrong lane.
 
Randy, below is the code, but the code isn't the problem; activating it is the problem.

Onefootout, I am color coding a label, so it's not in the tab order. I might try this solution and change the label to a textbox if nothing else works!
Thanks,Kristi
-------------------
Code:
If IsNull(Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate) Then
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.BackColor = vbRed
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.ForeColor = vbWhite
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.BackColor = vbRed
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.ForeColor = vbWhite

Me.lblStaffing.BackColor = vbRed
Me.lblStaffing.BackColor = vbWhite

ElseIf DatePart("d", Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate) >= 1 And DatePart("d", Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate) <= 15 And _
Now() - Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate < 30 Then
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.BackColor = 32768
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.ForeColor = vbWhite
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.BackColor = 32768
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.ForeColor = vbWhite
Forms![directorate program input]!lblStaffing.BackColor = 32768
Forms![directorate program input]!lblStaffing.ForeColor = vbWhite


ElseIf Now() - Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate > 30 And Now() - Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate < 40 Then
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.BackColor = vbYellow
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.ForeColor = vbBlack
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.BackColor = vbYellow
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.ForeColor = vbBlack
Forms![directorate program input]!lblStaffing.BackColor = vbYellow
Forms![directorate program input]!lblStaffing.ForeColor = vbBlack



ElseIf DatePart("d", Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate) > 15 And DatePart("d", Forms![directorate program input]![staffingcomplete subform].Form!txtStaffingCompleteDate) < 31 Then
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.BackColor = 65280
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingComplete.ForeColor = vbBlack
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.BackColor = 65280
Forms![directorate program input]![staffingcomplete subform].Form!lblStaffingCompleteDate.ForeColor = vbBlack
Forms![directorate program input]!lblStaffing.BackColor = 65280
Forms![directorate program input]!lblStaffing.ForeColor = vbBlack

End If
 
the only time it works properly is when the code is in the on current event and when I switch from design to form view
Please describe how you want this to behave from an end-user's point of view, not from a programmer's point of view. The above statement does not tell me how you want it to behave, since an end-user would not open a form from design to form view.

For example, do you want your code to fire when the user moves to an existing record?

 
How are ya kristi1023 . . .

. . . and if you move the code to the [blue]On Load[/blue] event? . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Randy700 and JoeatWork,

I want the code to be activated when the user opens the form. You're right the user won't be looking at the form in design view and switching to form view. This is my dilemma.

AceMan,

I tried the OnLoad event with no success.

Thank you All,
Kristi
 
How does the user get to this form?

Give us an example:

When the user opens the form, what colors are on the lblStaffingComplete label?

What is the value of the txtStaffingCompleteDate field?


Randy
 
Also, how are you determining that your code is not being reached? Are you just watching the form open to see if the label changes to the color you expect?

If you haven't done so already, place a break point at the beginning of your code to see if it is ever reached. If it is reached, step through the code to see which option is actually being evaluated.

When you say it "works correctly when opening from design mode", it indicates your code for opening it has restrictions (which would not be true if opening from design mode). You may be opening it with a filter, or perhaps in Add mode, etc. So it would help to see the code you actually use to open the form.

 
It's finally working! I moved the code to the On Mouse Move event of the Detail section of the form. Now let's just hope that the users will actually move their mouse! :)

Thank you all!
Kristi
 
kristi,

That may be a nice work-around, but it certainly is no solution to your problem. Why not provide us with some further information so we can help you fix it properly? So far, I haven't been able to recreate the problem.


Randy
 
I'm somewhat skeptical that you really want your code to fire on the mouse move event. It's going to be firing constantly when it doesn't have to.

If I understand your circumstances correctly, it really only needs to fire when:
1. You navigate to the record (i.e. the Current event)
2. The value of txtStaffingCompleteDate changes (probably the AfterUpdate event of that control)

In which case I would write a subroutine that contains your code, and call that subroutine when either of those two events occur. Using the mouse move event is like spraying machine gun fire when all you really need is the occasional sniper shot.

If you show us your code for opening the form, we may still be able to unravel this mystery. Or perhaps you open the form with macro, switchboard, etc., it doesn't matter, just let us know.

Also, the problem is you are relying on an event that doesn't really reflect the circumstances of when the label should change color. It could very well be confusing to the user to see something on the screen change just because they moved their mouse.

 
Randy & Joe,

Here's the code I use to open the form:

On Error GoTo Err_OpenProgReqs_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Directorate Program Input"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenProgReqs_Click:
Exit Sub
Err_OpenProgReqs_Click:
MsgBox Err.Description
Resume Exit_OpenProgReqs_Click

Before I moved the code to the On Mouse Move event, the label was always color coded red. I see both of your concerns, but I've tried so many other ways to get it to work w/ no success. I appreciate your recommendations and I will change the procedure if either of you think it will work.

Thank you,
Kristi
 
Give us an example:

When the user opens the form, what colors are on the lblStaffingComplete label?

What is the value of the txtStaffingCompleteDate field?


Randy
 
Randy,

lblStaffingComplete is always red no matter what the date is or if the date field is null.

lblStaffingComplete will be updated according to the code that I posted when I switch between design and form view, but as we've established users won't be doing this, so I need the code to function when the form opens.

Thank you again for your help!

Kristi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top