-
[RESOLVED] Monthview DayBold problem
I read every thread on here I can find about this but could not find a solution.
What I am doing:
I wrote a loop that goes through all the events added in the database for the specified loop and sets the .DayBold = True for those dates.
Well, it doesn't do anything when it runs. I did the bolding loop in a sub of its own and called it on form_load.
I call it again on monthview_dateclick() as well.
The dateclick searches the database for anything on the selected day and lists it in a simple listbox.
Here is the weird thing...If I click a date that actually has something stored in the database, it works perfectly. All the other dates for the month with events light up bold, but if I click any date that does not have anything scheduled, nothing happens.
Here is the code for my loop to bold the days:
Code:
Private Sub BoldDays()
currentMonth = MonthView1.Month
Call MainCon
Set RS = New ADODB.Recordset
RS.Open ("SELECT * FROM Calendar WHERE month = '" & currentMonth & "'"), Con, adOpenStatic, adLockOptimistic
Do Until RS.EOF
bDate = RS.Fields("date")
MonthView1.DayBold(bDate) = True
Loop
RS.Close
Con.Close
Set RS = Nothing
Set Con = Nothing
End Sub
That runs on startup and doesn't do anything. It runs on subsequent clicks of the calendar as well. But, it only seems to work if I click a day with something scheduled on that event.
I've tried forcing it to click the control for a specified date hoping that would do anything, but I cannot get them to go bold on first run, or when changing months in the calendar.
Any ideas?
-
Re: Monthview DayBold problem
Strange. I've placed a fresh control in a project then added this code to a command button:
Code:
Private Sub Command1_Click()
MonthView1.DayBold(Date) = True
MsgBox MonthView1.DayBold(Date)
End Sub
When I click it once, nothing happens, even the message box doesn't show. Second click works fine though. It's like it 'eats' the first one somehow...
-
Re: Monthview DayBold problem
Just tested and for me it works when clicking dates but it doesn't work on Form_load or Form_Activate, the only way i could bold multiple days was adding the code in a Commandbutton event, weird.
EDIT:
Quote:
When I click it once, nothing happens, even the message box doesn't show. Second click works fine though. It's like it 'eats' the first one somehow...
Yes, that's because the Commandbutton is not the control in focus when the Form loads, first click takes focus and seconds fires the event, but you're right this shouldn't be happening :sick:
Another EDIT: Changing all days in the month works fine for me:
Code:
Private Sub Command1_Click()
Dim i As Long
For i = 1 To 30
Me.MonthView1.DayBold(i & "/4/2010") = True
Next
End Sub
-
Re: Monthview DayBold problem
Sounds like the problems I have been running into.
I have even tried calling the dateclick event after it runs the first time to see that helps.
I cannot get it to work on the first run, but can get it when clicking any date that returns a stored date.
Its like some weird voodoo or something.
-
Re: Monthview DayBold problem
Take a look at my reply in this related thread. Maybe that would be a better solution?
-
Re: Monthview DayBold problem
-
Re: Monthview DayBold problem
Thanks both for those links.
I had actually read both of those articles before posting this one. But neither of them solved my problem
@koolsid: I tried that too.
In any given month, there may or may not be events scheduled for certain days. Sometimes multiple events in the same day.
So, on form load, I need it to process the current month, go through and bold any dates that have saved events. Then, have it do the same if the month is changed.
Currently, it works only if I click a date that does have something for it.
So, if I have something in the database for 4/15/2010, 4/21/2010, 4/27/2010...I need those 3 dates to be bold on the calendar as soon as the form loads so they are clearly visible.
Right now, if I click any of those 3 dates on the calendar control, they all turn bold, but if I click any other dates, nothing happens.
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
Capp
Currently, it works only if I click a date that does have something for it.
That's what your BoldDays Sub does, but why it's doing it on click event? what's the code in your Click event?
-
Re: Monthview DayBold problem
Here is the code for clicking the monthview. It just does a basic query for any events for the date clicked and lists them. Then it calls the BoldDays Sub afterwards.
Code:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
lstEvents.Clear
strDate = MonthView1.Value
lblTitle.Caption = "Events for: " & strDate
Call MainCon
Set RS = New ADODB.Recordset
RS.Open ("SELECT * FROM Calendar WHERE date = '" & MonthView1.Value & "'"), Con, adOpenStatic, adLockOptimistic
If RS.EOF Then
RS.Close
Con.Close
Set RS = Nothing
Set Con = Nothing
Exit Sub
End If
Do Until RS.EOF
lstEvents.AddItem RS.Fields("event")
RS.MoveNext
Loop
RS.Close
Con.Close
Set RS = Nothing
Set Con = Nothing
BoldDays 'call the sub to bold days
End Sub
-
Re: Monthview DayBold problem
In the link I posted in #5 above. Similar problems were experienced, especially if clicking the forward/back buttons in the view very fast. Updating via the Click or similar events didn't always update the view properly. In that link I suggested to use the callback function the view provided and no matter how fast the monthview changed, all bolded items were displayed correctly.
Bottom line, suggest using the callback event -- that's what it was created for.
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
LaVolpe
In the link I posted in #5 above. Similar problems were experienced, especially if clicking the forward/back buttons in the view very fast. Updating via the Click or similar events didn't always update the view properly. In that link I suggested to use the callback function the view provided and no matter how fast the monthview changed, all bolded items were displayed correctly.
Bottom line, suggest using the callback event -- that's what it was created for.
With risks of looking an idiot, going by what I have already, how would I use the callback function? I read over your description and what the OP has is way more complicated that what I am using. Not sure how to go about throwing this in my program and getting it to work.
Thank You btw
-
Re: Monthview DayBold problem
I've run into this behavior with other controls.
Try this:
Code:
Option Explicit
Private Sub Form_Load()
Me.Show
Me.Refresh
'
MonthView1.DayBold(Date - 1) = True
MonthView1.DayBold(Date + 1) = True
End Sub
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
Capp
With risks of looking an idiot, going by what I have already, how would I use the callback function? I read over your description and what the OP has is way more complicated that what I am using. Not sure how to go about throwing this in my program and getting it to work.
Thank You btw
What database field types is Date and Month? String, date/time, long/number.... ?
-
Re: Monthview DayBold problem
The date is saved as plain text, so String in format m/dd/yyyy.
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
Capp
Right now, if I click any of those 3 dates on the calendar control, they all turn bold, but if I click any other dates, nothing happens.
Offcourse nothing happens because inside that click event you're calling BoldDays that just Bolds dates found in db. You didn't add code to bold the date the user clicked, like:
Code:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
MonthView1.DayBold(DateClicked) = True
End Sub
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
jcis
Offcourse nothing happens because inside that click event you're calling BoldDays that just Bolds dates found in db. You didn't add code to bold the date the user clicked, like:
Code:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
MonthView1.DayBold(DateClicked) = True
End Sub
I don't want the day clicked to turn bold.
I only want days to be bold that have saved events for those dates in the database.
-
Re: Monthview DayBold problem
Oh i missunderstood, sorry.
About doing it when the Form loads, if you do it in event Form_Activate and Refresh the Form before it ends (as DrUnicode said) then it works, it seems it only works when the Form is visible..
Code:
Private Sub Form_Activate()
Me.Refresh
MonthView1.DayBold(Date) = True '(You would be calling your BoldDays here)
End Sub
..Or use the CallBack as Lavolpe said.
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
jcis
Oh i missunderstood, sorry.
About doing it when the Form loads, if you do it in event Form_Activate and Refresh the Form before it ends (as DrUnicode said) then it works, it seems it only works when the Form is visible..
Code:
Private Sub Form_Activate()
Me.Refresh
MonthView1.DayBold(Date) = True '(You would be calling your BoldDays here)
End Sub
..Or use the CallBack as Lavolpe said.
Ok, almost there.
By doing this on the form_activate event, it does bold all the necessary days for the initial month on startup. However, if I change months, it requires clicking the control again on a known day to get them bold again.
Any ideas on this one?
As mentioned, I don't know how to use the callback mentioned above with what I have already.
-
Re: Monthview DayBold problem
Try dropping the WHERE clause and set them all at once:
"SELECT * FROM Calendar"
-
Re: Monthview DayBold problem
After setting initially in Load or Activate, this appears to work:
Code:
Private Sub MonthView1_Click()
BoldDays
End Sub
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
DrUnicode
Try dropping the WHERE clause and set them all at once:
"SELECT * FROM Calendar"
I initially did do that, but since there are scheduled events for dates much further ahead of what the current display shows, it gives me an error telling me the date does not fall within the mindate/maxdate.
-
Re: Monthview DayBold problem
I know this problem. :D
I use this code:
Code:
Dim rs As ADODB.Recordset
Private Sub Form_Load()
'
' your code....
'
Set rs = New ADODB.Recordset
' CN is your ADODB.Connection already open
' I named my MonthView control as: 'Calendar1'
Calendar1.Value = Now ' this call GetDayBold event
End Sub
Public Sub Calendar1_GetDayBold(ByVal StartDate As Date, ByVal count As Integer, State() As Boolean)
' first check if there are events in the days-range
' please note that calendar show 'ever' 42 days, therefore you have
' to deal with all 42 days, 'ever'
Dim sSQL As String
sSQL = "SELECT myDate FROM myTable "
sSQL = sSQL & " WHERE myDate BETWEEN #" & StartDate & "#
sSQL = sSQL & " AND #" & DateAdd("d", 41, StartDate) & "# "
If rs.State = 1 Then rs.Close
rs.Open sSQL, CN, adOpenStatic, adLockOptimistic
' If rs is empty, then reset all days to No-BOLD state
' i.e. when you change month and the month hasn't events
If rs.EOF = 0 Then
For i = 1 To 42
Calendar1.DayBold(Calendar1.VisibleDays(i)) = False
Next i
Exit Sub
End If
' there are events: set to Bold only the related days:
For i = 0 To count - 1
thisDay = DateAdd("d", i, StartDate)
rs.Find "myDate = #" & thisDay & "#", , adSearchForward, 1
If Not rs.EOF Then
State(i) = True ' set Bold
Else
State(i) = False ' reset to No-Bold
End If
Next
Calendar1.Refresh
End Sub
:wave:
-
Re: Monthview DayBold problem
Gibra's post is what I was trying to get you to consider in post #5 above.
Here are some comments regarding the parameters of that event, depending on how your monthview is set up (single month, multiple months)
StartDate is the 1st date displayed on the month view, not necessarily 1st day of the month
Count is the number of days displayed on the month view currently
-- can be partial previous month
-- should be entire current month
-- can be partial next month
State() is a boolean array
-- State(0) = StartDate's bold value
-- State(Count-1) = Bold value of last date on view
Some suggestions regarding Gibra's snippet.
1. Hardcoding 1 to 42 is custom for Gibra's purpose. Generally, one won't hard code a range
2. Do not use .DayBold property to set the boldness, use the State() array passed from the event
3. To get the the last day displayed in the monthview: DateAdd("d", Count-1, StartDate)
4. Suggest changing your query to retrieve all dates from your DB in the Start/End date range. Then updating the State() array as Gibra did in the final For:next loop.
-
Re: Monthview DayBold problem
Edit: Forget this reply. I'm an idiot. Will update when I'm not. :)
-
Re: Monthview DayBold problem
Ummm, two things. I don't intend to sound demeaning; just trying to highlight that you cannot just blindly paste stuff into your project and expect it to work.
1. Is your monthview named Calendar1? Explains why it was never called.
2. You CANNOT just copy and paste that code, it MUST be modified for your project.
:: the control name is not the same
:: the ADODB connection, recordset and query strings are most likely not even close
:: I'm sure there are other differences too
-
Re: Monthview DayBold problem
OK, it is working perfectly now.
Here is the final code I used:
Code:
Private Sub MonthView1_GetDayBold(ByVal StartDate As Date, ByVal Count As Integer, State() As Boolean)
Dim i As Integer
Dim thisDay As Date
Dim sSQL As String
sSQL = "SELECT * FROM Calendar "
sSQL = sSQL & " WHERE date BETWEEN #" & StartDate & "# "
sSQL = sSQL & " AND #" & DateAdd("d", 41, StartDate) & "# "
Call MainCon
Set RS = New ADODB.Recordset
RS.Open sSQL, Con, adOpenStatic, adLockOptimistic
' there are events: set to Bold only the related days:
For i = 0 To Count - 1
thisDay = DateAdd("d", i, StartDate)
RS.Find "date = #" & thisDay & "#", , adSearchForward, 1
If Not RS.EOF Then
State(i) = True ' set Bold
Else
State(i) = False ' reset to No-Bold
End If
Next
MonthView1.Refresh
End Sub
Thank you all very much. :thumb:
-
Re: Monthview DayBold problem
Quote:
Originally Posted by
LaVolpe
Ummm, two things. I don't intend to sound demeaning; just trying to highlight that you cannot just blindly paste stuff into your project and expect it to work.
1. Is your monthview named Calendar1? Explains why it was never called.
2. You CANNOT just copy and paste that code, it MUST be modified for your project.
:: the control name is not the same
:: the ADODB connection, recordset and query strings are most likely not even close
:: I'm sure there are other differences too
No offense taken. I didn't just copy and paste the code and expect it to work. I pasted it as written and modified it to fit my needs. The only thing I didn't do was change the Sub Name. Which is why I edited my post.
The rest of it was setup correctly for how I needed it, so there wasn't much editing needing to be done.
Thank you for your help.