|
-
Apr 20th, 2010, 10:46 AM
#1
Thread Starter
Hyperactive Member
[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?
-
Apr 20th, 2010, 10:58 AM
#2
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...
-
Apr 20th, 2010, 11:13 AM
#3
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:
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 
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
Last edited by jcis; Apr 20th, 2010 at 12:07 PM.
-
Apr 20th, 2010, 12:01 PM
#4
Thread Starter
Hyperactive Member
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.
-
Apr 20th, 2010, 12:58 PM
#5
Re: Monthview DayBold problem
Take a look at my reply in this related thread. Maybe that would be a better solution?
-
Apr 20th, 2010, 01:23 PM
#6
Re: Monthview DayBold problem
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 20th, 2010, 02:12 PM
#7
Thread Starter
Hyperactive Member
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.
-
Apr 20th, 2010, 02:25 PM
#8
Re: Monthview DayBold problem
 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?
-
Apr 20th, 2010, 02:45 PM
#9
Thread Starter
Hyperactive Member
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
-
Apr 20th, 2010, 02:53 PM
#10
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.
-
Apr 20th, 2010, 03:14 PM
#11
Thread Starter
Hyperactive Member
Re: Monthview DayBold problem
 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
-
Apr 20th, 2010, 03:16 PM
#12
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
-
Apr 20th, 2010, 03:32 PM
#13
Re: Monthview DayBold problem
 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.... ?
-
Apr 20th, 2010, 03:44 PM
#14
Thread Starter
Hyperactive Member
Re: Monthview DayBold problem
The date is saved as plain text, so String in format m/dd/yyyy.
-
Apr 20th, 2010, 03:54 PM
#15
Re: Monthview DayBold problem
 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
-
Apr 20th, 2010, 03:57 PM
#16
Thread Starter
Hyperactive Member
Re: Monthview DayBold problem
 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.
-
Apr 20th, 2010, 04:13 PM
#17
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.
-
Apr 20th, 2010, 04:31 PM
#18
Thread Starter
Hyperactive Member
Re: Monthview DayBold problem
 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.
Last edited by Capp; Apr 20th, 2010 at 04:36 PM.
-
Apr 20th, 2010, 04:41 PM
#19
Re: Monthview DayBold problem
Try dropping the WHERE clause and set them all at once:
"SELECT * FROM Calendar"
-
Apr 20th, 2010, 04:54 PM
#20
Re: Monthview DayBold problem
After setting initially in Load or Activate, this appears to work:
Code:
Private Sub MonthView1_Click()
BoldDays
End Sub
-
Apr 20th, 2010, 04:57 PM
#21
Thread Starter
Hyperactive Member
Re: Monthview DayBold problem
 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.
-
Apr 20th, 2010, 05:13 PM
#22
Re: Monthview DayBold problem
I know this problem. 
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
-
Apr 21st, 2010, 09:16 AM
#23
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.
-
Apr 21st, 2010, 10:03 AM
#24
Thread Starter
Hyperactive Member
Re: Monthview DayBold problem
Edit: Forget this reply. I'm an idiot. Will update when I'm not.
Last edited by Capp; Apr 21st, 2010 at 10:08 AM.
-
Apr 21st, 2010, 10:11 AM
#25
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
-
Apr 21st, 2010, 10:20 AM
#26
Thread Starter
Hyperactive Member
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.
-
Apr 21st, 2010, 10:23 AM
#27
Thread Starter
Hyperactive Member
Re: Monthview DayBold problem
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|