View Single Post
 
Old 09-28-2013, 03:43 PM
skarden skarden is offline Windows XP Office 2003
Novice
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 27
skarden is on a distinguished road
Question Userform label bordercolor not controllable if click label

I need a pop-up calendar for a Word macro at my workplace. I'm using Office 2010. They won't let me bring in the calendar control, change the registry, etc., so I am creating a calendar. I don't like the look of using buttons for the dates so I'm using labels. I want the date centered horizontally and vertically in its "square" and I wanted a border around the outside of the date's square when it was selected.

To get the date to center both horizontally in its "square" I used the double label box trick. That is, for the upper left date area, "d1", I created a 24 x 24 label called "d1Back" (which is the size of the date's square). I then created another label "d1" that I turned auto-size to True, set its value to "1", placed it on top of d1Back and then aligned their centers and middles.

Because a month can start on a Saturday I created 6 rows of 7 dates, or 42 pairs of "dX", "dXBack" lables.

I then wrote a click routine for each (obviously passing the correct # for each date). Here it is for the d1 pair:

Private Sub d1_Click()
Selected_Day ("1")
End Sub

Private Sub d1Back_Click()
Selected_Day ("1")
End Sub

Which Calls Selected_Day. This loops through all the "back" controls and makes the border white if it isn't the selected one, and blue if it is.

Private Sub Selected_Day(sD As String)
Dim i As Integer
For i = 1 To 42 'Need 42 boxes to account for month starting different days
If i = sD Then
Controls("d" & i & "Back").BorderColor = &HFF0000 'Blue
Else
Controls("d" & i & "Back").BorderColor = &HFFFFFF 'White
End If
Next i
End Sub

When I click on the inner box, that is, where the actual date is ("d1" in this example) it works fine. However, (and this is where my problem is), if I click on the "back" label, not only doesn't the border change that time, but it will never change again, even if I click the inner date control, until I close and reopen the form.

For example, for September 2013, the 1st was a Sunday and that is my "d1" box. If I click the "1" I get the blue border around d1Back. If I click the 2 of September 2nd I get the border around d2Back. If I click the 1 of September 1st, I again get the border around d1Back. However, if I ever click the d1Back portion of the square (and it doesn't matter if I had just clicked d1 or another date just before that) the label border won't change! Even if I click another date and then click the "1" of September 1 again!

I've used [F9] to stop when I get to the Selected_Day For loop and [F8] to step through it to make sure everything is firing properly, and it is.

I can't figure out for the life of me why I can't change the label's bordercolor once I've clicked on the label.

Help please,

Stuart

Last edited by skarden; 09-28-2013 at 03:47 PM. Reason: Spelling typo
Reply With Quote