473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

change colour of text if a certain field is "cancelled"

This is a ADezii's Db


All i'm trying trying to do is to get the text to change the text colour depending on the status of the which comes from the booking table.

tbl_bookings.status ("confirmed", "cancelled", "provisional")

below is the block which seams to change the colours of the text in the boxes.

Expand|Select|Wrap|Line Numbers
  1.         If lngBlockDate = lngSystemDate Then
  2.           ctlDayBlock.BackColor = QBColor(13)
  3.           ctlDayBlock.ForeColor = QBColor(15)
  4.           Set ctlSystemDateBlock = ctlDayBlock
  5.           blnSystemDateIsShown = True
  6.         Else
  7.           ctlDayBlock.BackColor = 16777215      'Background Main cell colour
  8.           ctlDayBlock.ForeColor = 8388608       ' txt colour
  9.         End If
  10.  
  11.           ctlDayBlock.Visible = True
  12.           ctlDayBlock.Enabled = True
  13.           ctlDayBlock.Tag = lngBlockDate
  14.  
  15.  
  16.  
so guessing i need to change add in an extra if statement,

Expand|Select|Wrap|Line Numbers
  1. If status = "cancled" Then
as well as alter the SQL to pull through the "status" section?

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * From tbl_Bookings "
  2. strSQL = strSQL & "WHERE tbl_Bookings.[MeetingDate] Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
  3.                   " ORDER BY tbl_Bookings.[EventID];"
  4.  
and also add in a variable at the top???

any help???? i'm a little lost.
Nov 4 '16 #1

✓ answered by jforbes

This is what I came up with, it allows for each appointment to be color coded both the Foreground and Background. I don't know if you need all that flexibility, but it was only a couple lines more of code.



To get this to work, you will need to change the .TextFormat property to "Rich Text" for all 42 TextBoxes. Just select them all and change the property once.

The following code will need to be placed at the Top of the Code for the fdlgEventDetails(frmCalendar):
Expand|Select|Wrap|Line Numbers
  1. Private Const nAppointmentTemplate = "<div><font color={2} style=""BACKGROUND-COLOR:{3}"">[{0}] - {1}</font></div>"
This sets up a constant, a template for the display text.

The following code is the update to make it all work:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PopulateCalendar()
  2. On Error GoTo Err_PopulateCalendar
  3.  
  4. Dim strFirstOfMonth As String, bytFirstWeekdayOfMonth As Byte, bytBlockCounter As Byte
  5. Dim bytBlockDayOfMonth As Byte, lngBlockDate As Long, ctlDayBlock As Control
  6. Dim bytDaysInMonth As Byte, bytEventDayOfMonth As Byte, lngFirstOfMonth As Long
  7. Dim lngLastOfMonth As Long, lngFirstOfNextMonth As Long, lngLastOfPreviousMonth As Long
  8. Dim lngEventDate As Long, bytBlankBlocksBefore As Byte, bytBlankBlocksAfter As Byte
  9. Dim astrCalendarBlocks(1 To 42) As String, db As Database, rstEvents As Recordset
  10. Dim strSelectEvents As String, strEvent As String, strPlatoons As String
  11. Dim intMonth As Integer, intYear As Integer, lngSystemDate As Long  'CFB added 1-25-08
  12. Dim ctlSystemDateBlock As Control, blnSystemDateIsShown As Boolean  'CFB added 1-25-08
  13. Dim strSQL As String    'Added 4/16/2008
  14. Dim blnRetVal
  15. Dim sBackgroundColor As String, sForeColor As String
  16.  
  17. lngSystemDate = Date    'CFB added 1-25-08
  18. intMonth = objCurrentDate.Month
  19. intYear = objCurrentDate.Year
  20. lstEvents.Visible = False
  21. lblEventsOnDate.Visible = False
  22. lblMonth.Caption = MonthAndYear(intMonth, intYear)
  23. strFirstOfMonth = Str(intMonth) & "/1/" & Str(intYear)
  24.   'ADezii
  25.   'NOTE: Will work in the UK (United Kingdom) and other European Nations
  26.   'strFirstOfMonth = "1/" & Str(intMonth) & Str(intYear)
  27. bytFirstWeekdayOfMonth = Weekday(strFirstOfMonth)
  28. lngFirstOfMonth = DateSerial(intYear, intMonth, 1)
  29. lngFirstOfNextMonth = DateSerial(intYear, intMonth + 1, 1)
  30. lngLastOfMonth = lngFirstOfNextMonth - 1
  31. lngLastOfPreviousMonth = lngFirstOfMonth - 1
  32. bytDaysInMonth = lngFirstOfNextMonth - lngFirstOfMonth
  33. bytBlankBlocksBefore = bytFirstWeekdayOfMonth - 1
  34. bytBlankBlocksAfter = 42 - (bytBlankBlocksBefore + bytDaysInMonth)
  35.  
  36. Set db = CurrentDb
  37.  
  38. strSQL = "SELECT * From tblEvents "
  39. 'strSQL = strSQL & "WHERE tblEvents.Status <> 'Cancelled' And tblEvents.[StartDate] Between " & lngFirstOfMonth & " And " & lngLastOfMonth &
  40. strSQL = strSQL & "WHERE tblEvents.[StartDate] Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
  41.                   " ORDER BY tblEvents.[StartDate];"
  42.  
  43. Set rstEvents = db.OpenRecordset(strSQL)    'Added 4/16/2008
  44.  
  45. Do While Not rstEvents.EOF
  46.  
  47.   ' Determine Background Color
  48.   Select Case Nz(rstEvents![Status], "Tentative")
  49.     Case "Tentative", "Confirmed", "Completed"
  50.       sForeColor = "#000077"
  51.       sBackgroundColor = "#FFFFFF"
  52.     Case "Cancelled"
  53.       sForeColor = "#AA0000"
  54.       sBackgroundColor = "#FFFF00"
  55.     Case Else
  56.       sForeColor = "#000077"
  57.       sBackgroundColor = "#FFFFFF"
  58.   End Select
  59.  
  60.   ' Generate Display Text
  61.   'strEvent = "[" & rstEvents![EventID] & "] - " & rstEvents![EventName]
  62.   strEvent = nAppointmentTemplate
  63.   strEvent = Replace(strEvent, "{0}", Nz(rstEvents![EventID], ""))
  64.   strEvent = Replace(strEvent, "{1}", Nz(rstEvents![EventName], ""))
  65.   strEvent = Replace(strEvent, "{2}", sForeColor)
  66.   strEvent = Replace(strEvent, "{3}", sBackgroundColor)
  67.  
  68.   ' Find Day
  69.   bytEventDayOfMonth = (rstEvents!StartDate - lngLastOfPreviousMonth)
  70.   bytBlockCounter = bytEventDayOfMonth + bytBlankBlocksBefore
  71.  
  72.     If astrCalendarBlocks(bytBlockCounter) <> "" Then
  73.       astrCalendarBlocks(bytBlockCounter) = _
  74.       astrCalendarBlocks(bytBlockCounter) & vbNewLine & strEvent
  75.     Else
  76.       astrCalendarBlocks(bytBlockCounter) = strEvent
  77.     End If
  78.     rstEvents.MoveNext
  79. Loop
  80. ...

16 1371
jforbes
1,107 Expert 1GB
Would you post the entire method?

I don't know that database and it's a little hard to be 100% sure with only the snippets that have been posted.
Nov 4 '16 #2
below is the block which i think populates the blocks which are on the main calendar form in a txt box. (for example txtDayBlock01). so this is why im not sure if what to do as im not sure if it is possible to have multiple formats within one textbox?


Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub PopulateCalendar()
  3. On Error GoTo Err_PopulateCalendar
  4.  
  5. Dim strFirstOfMonth As String, bytFirstWeekdayOfMonth As Byte, bytBlockCounter As Byte
  6. Dim bytBlockDayOfMonth As Byte, lngBlockDate As Long, ctlDayBlock As Control
  7. Dim bytDaysInMonth As Byte, bytEventDayOfMonth As Byte, lngFirstOfMonth As Long
  8. Dim lngLastOfMonth As Long, lngFirstOfNextMonth As Long, lngLastOfPreviousMonth As Long
  9. Dim lngEventDate As Long, bytBlankBlocksBefore As Byte, bytBlankBlocksAfter As Byte
  10. Dim astrCalendarBlocks(1 To 42) As String, db As Database, rstEvents As Recordset
  11. Dim strSelectEvents As String, strEvent As String, strPlatoons As String
  12. Dim intMonth As Integer, intYear As Integer, lngSystemDate As Long  'CFB added 1-25-08
  13. Dim ctlSystemDateBlock As Control, blnSystemDateIsShown As Boolean  'CFB added 1-25-08
  14. Dim strSQL As String    'Added 4/16/2008
  15. Dim blnRetVal
  16.  
  17. lngSystemDate = Date    'CFB added 1-25-08
  18. intMonth = objCurrentDate.Month
  19. intYear = objCurrentDate.Year
  20. lstEvents.Visible = False
  21. lblEventsOnDate.Visible = False
  22. lblMonth.caption = MonthAndYear(intMonth, intYear)
  23. strFirstOfMonth = "1/" & Str(intMonth) & Str(intYear)
  24. bytFirstWeekdayOfMonth = Weekday(strFirstOfMonth, vbMonday)  'add , vbmonday tostart monday
  25. 'bytFirstWeekdayOfMonth = Weekday(strFirstOfMonth)  'starts sunday
  26. lngFirstOfMonth = DateSerial(intYear, intMonth, 1)
  27. lngFirstOfNextMonth = DateSerial(intYear, intMonth + 1, 1)
  28. lngLastOfMonth = lngFirstOfNextMonth - 1
  29. lngLastOfPreviousMonth = lngFirstOfMonth - 1 'highlight of current day
  30. bytDaysInMonth = lngFirstOfNextMonth - lngFirstOfMonth
  31. bytBlankBlocksBefore = bytFirstWeekdayOfMonth - 1
  32. bytBlankBlocksAfter = 42 - (bytBlankBlocksBefore + bytDaysInMonth)
  33.  
  34.  
  35. Set db = CurrentDb
  36.  
  37. strSQL = "SELECT * From tbl_Bookings "
  38. strSQL = strSQL & "WHERE tbl_Bookings.[MeetingDate] Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
  39.                   " ORDER BY tbl_Bookings.[EventID];"
  40.  
  41. Set rstEvents = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)    'Added 4/16/2008
  42.  
  43. Do While Not rstEvents.EOF
  44.   strEvent = rstEvents![EventTitle] ' & vbCrLf & rstEvents![StartTime] & " - " & rstEvents![EndTime] 'have date and time
  45.   bytEventDayOfMonth = (rstEvents!MeetingDate - lngLastOfPreviousMonth)
  46.   bytBlockCounter = bytEventDayOfMonth + bytBlankBlocksBefore
  47.     If astrCalendarBlocks(bytBlockCounter) <> "" Then
  48.       astrCalendarBlocks(bytBlockCounter) = _
  49.       astrCalendarBlocks(bytBlockCounter) & vbNewLine & strEvent
  50.     Else
  51.       astrCalendarBlocks(bytBlockCounter) = strEvent
  52.     End If
  53.     rstEvents.MoveNext
  54. Loop
  55.  
  56. For bytBlockCounter = 1 To 42                       'blank blocks at start of month
  57.   Select Case bytBlockCounter
  58.     Case Is < bytFirstWeekdayOfMonth
  59.       astrCalendarBlocks(bytBlockCounter) = ""
  60.       ReferenceABlock ctlDayBlock, bytBlockCounter
  61.       ctlDayBlock.BackColor = 12632256
  62.       ctlDayBlock = ""
  63.       ctlDayBlock.Enabled = False
  64.       ctlDayBlock.Tag = ""
  65.     Case Is > bytBlankBlocksBefore + bytDaysInMonth 'blank blocks at end of month
  66.       astrCalendarBlocks(bytBlockCounter) = ""
  67.       ReferenceABlock ctlDayBlock, bytBlockCounter
  68.       ctlDayBlock.BackColor = 12632256
  69.       ctlDayBlock = ""
  70.       ctlDayBlock.Enabled = False
  71.       ctlDayBlock.Tag = ""
  72.         If bytBlankBlocksAfter > 6 And bytBlockCounter > 35 Then
  73.           ctlDayBlock.Visible = False
  74.         End If
  75.     Case Else   'blocks that hold days of the month
  76.       bytBlockDayOfMonth = bytBlockCounter - bytBlankBlocksBefore
  77.       ReferenceABlock ctlDayBlock, bytBlockCounter
  78.       lngBlockDate = lngLastOfPreviousMonth + bytBlockDayOfMonth 'block's date
  79.         If bytBlockDayOfMonth < 10 Then
  80.           ctlDayBlock = Space(2) & bytBlockDayOfMonth & _
  81.                         vbNewLine & astrCalendarBlocks(bytBlockCounter)
  82.         Else
  83.           ctlDayBlock = bytBlockDayOfMonth & _
  84.                         vbNewLine & astrCalendarBlocks(bytBlockCounter)
  85.         End If
  86.  
  87.         'If this block is the system date, change its color (CFB 1-25-08)
  88.         If lngBlockDate = lngSystemDate Then
  89.           ctlDayBlock.BackColor = QBColor(13)
  90.           ctlDayBlock.ForeColor = QBColor(15)
  91.           Set ctlSystemDateBlock = ctlDayBlock
  92.           blnSystemDateIsShown = True
  93.         Else
  94.           ctlDayBlock.BackColor = 16777215      'Background Main cell colour
  95.           ctlDayBlock.ForeColor = 8388608       ' txt colour
  96.         End If
  97.  
  98. '        If "tbl_bookings.[Status]" = "Cancelled" Then
  99. '            ctlDayBlock.ForeColor = 12632256
  100. '        Else
  101. 'ctlDayBlock.BackColor = 16777215 '
  102. 'ctlDayBlock.ForeColor = 8388608
  103. '       End If
  104.  
  105.           ctlDayBlock.Visible = True
  106.           ctlDayBlock.Enabled = True
  107.           ctlDayBlock.Tag = lngBlockDate
  108.   End Select
  109. Next
  110.  
  111. 'If the system date is in this month, show its events (CFB added 1-25-08)
  112. If blnSystemDateIsShown Then
  113.   PopulateEventsList ctlSystemDateBlock
  114. End If
  115.  
  116. Call PopulateYearListBox    'Added by ADezii on 1/28/2008 - suggested by CFB
  117.  
  118. Exit_PopulateCalendar:
  119.   Exit Sub
  120. Err_PopulateCalendar:
  121.   MsgBox Err.Description, vbExclamation, "Error inPopulateCalendar()"
  122.   Resume Exit_PopulateCalendar
  123. End Sub
  124.  
  125.  
let me know if you want me to post the db.
Nov 7 '16 #3
jforbes
1,107 Expert 1GB
This would be my best guess:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PopulateCalendar()
  2. On Error GoTo Err_PopulateCalendar
  3.  
  4.     Dim strFirstOfMonth As String, bytFirstWeekdayOfMonth As Byte, bytBlockCounter As Byte
  5.     Dim bytBlockDayOfMonth As Byte, lngBlockDate As Long, ctlDayBlock As Control
  6.     Dim bytDaysInMonth As Byte, bytEventDayOfMonth As Byte, lngFirstOfMonth As Long
  7.     Dim lngLastOfMonth As Long, lngFirstOfNextMonth As Long, lngLastOfPreviousMonth As Long
  8.     Dim lngEventDate As Long, bytBlankBlocksBefore As Byte, bytBlankBlocksAfter As Byte
  9.     Dim astrCalendarBlocks(1 To 42) As String, db As Database, rstEvents As Recordset
  10.     Dim astrCalendarBlocksStatus(1 To 42) As String
  11.     Dim strSelectEvents As String, strEvent As String, strPlatoons As String
  12.     Dim intMonth As Integer, intYear As Integer, lngSystemDate As Long  'CFB added 1-25-08
  13.     Dim ctlSystemDateBlock As Control, blnSystemDateIsShown As Boolean  'CFB added 1-25-08
  14.     Dim strSQL As String    'Added 4/16/2008
  15.     Dim blnRetVal
  16.  
  17.     lngSystemDate = Date    'CFB added 1-25-08
  18.     intMonth = objCurrentDate.Month
  19.     intYear = objCurrentDate.Year
  20.     lstEvents.Visible = False
  21.     lblEventsOnDate.Visible = False
  22.     lblMonth.Caption = MonthAndYear(intMonth, intYear)
  23.     strFirstOfMonth = "1/" & Str(intMonth) & Str(intYear)
  24.     bytFirstWeekdayOfMonth = Weekday(strFirstOfMonth, vbMonday)  'add , vbmonday tostart monday
  25.     'bytFirstWeekdayOfMonth = Weekday(strFirstOfMonth)  'starts sunday
  26.     lngFirstOfMonth = DateSerial(intYear, intMonth, 1)
  27.     lngFirstOfNextMonth = DateSerial(intYear, intMonth + 1, 1)
  28.     lngLastOfMonth = lngFirstOfNextMonth - 1
  29.     lngLastOfPreviousMonth = lngFirstOfMonth - 1 'highlight of current day
  30.     bytDaysInMonth = lngFirstOfNextMonth - lngFirstOfMonth
  31.     bytBlankBlocksBefore = bytFirstWeekdayOfMonth - 1
  32.     bytBlankBlocksAfter = 42 - (bytBlankBlocksBefore + bytDaysInMonth)
  33.  
  34.  
  35.     Set db = CurrentDb
  36.  
  37.     strSQL = "SELECT * From tbl_Bookings "
  38.     strSQL = strSQL & "WHERE tbl_Bookings.[MeetingDate] Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
  39.                       " ORDER BY tbl_Bookings.[EventID];"
  40.  
  41.     Set rstEvents = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)    'Added 4/16/2008
  42.  
  43.     Do While Not rstEvents.EOF
  44.       strEvent = rstEvents![EventTitle] ' & vbCrLf & rstEvents![StartTime] & " - " & rstEvents![EndTime] 'have date and time
  45.       bytEventDayOfMonth = (rstEvents!MeetingDate - lngLastOfPreviousMonth)
  46.       bytBlockCounter = bytEventDayOfMonth + bytBlankBlocksBefore
  47.         If astrCalendarBlocks(bytBlockCounter) <> "" Then
  48.           astrCalendarBlocks(bytBlockCounter) = _
  49.           astrCalendarBlocks(bytBlockCounter) & vbNewLine & strEvent
  50.         Else
  51.           astrCalendarBlocks(bytBlockCounter) = strEvent
  52.         End If
  53.         astrCalendarBlocksStatus(bytBlockCounter) = Nz(rstEvents![Status], "")
  54.         rstEvents.MoveNext
  55.     Loop
  56.  
  57.     For bytBlockCounter = 1 To 42                       'blank blocks at start of month
  58.       Select Case bytBlockCounter
  59.         Case Is < bytFirstWeekdayOfMonth
  60.           astrCalendarBlocks(bytBlockCounter) = ""
  61.           ReferenceABlock ctlDayBlock, bytBlockCounter
  62.           ctlDayBlock.BackColor = 12632256
  63.           ctlDayBlock = ""
  64.           ctlDayBlock.Enabled = False
  65.           ctlDayBlock.Tag = ""
  66.         Case Is > bytBlankBlocksBefore + bytDaysInMonth 'blank blocks at end of month
  67.           astrCalendarBlocks(bytBlockCounter) = ""
  68.           ReferenceABlock ctlDayBlock, bytBlockCounter
  69.           ctlDayBlock.BackColor = 12632256
  70.           ctlDayBlock = ""
  71.           ctlDayBlock.Enabled = False
  72.           ctlDayBlock.Tag = ""
  73.             If bytBlankBlocksAfter > 6 And bytBlockCounter > 35 Then
  74.               ctlDayBlock.Visible = False
  75.             End If
  76.         Case Else   'blocks that hold days of the month
  77.           bytBlockDayOfMonth = bytBlockCounter - bytBlankBlocksBefore
  78.           ReferenceABlock ctlDayBlock, bytBlockCounter
  79.           lngBlockDate = lngLastOfPreviousMonth + bytBlockDayOfMonth 'block's date
  80.             If bytBlockDayOfMonth < 10 Then
  81.               ctlDayBlock = Space(2) & bytBlockDayOfMonth & _
  82.                             vbNewLine & astrCalendarBlocks(bytBlockCounter)
  83.             Else
  84.               ctlDayBlock = bytBlockDayOfMonth & _
  85.                             vbNewLine & astrCalendarBlocks(bytBlockCounter)
  86.             End If
  87.  
  88.             'If this block is the system date, change its color (CFB 1-25-08)
  89.             If lngBlockDate = lngSystemDate Then
  90.               ctlDayBlock.BackColor = QBColor(13)
  91.               ctlDayBlock.ForeColor = QBColor(15)
  92.               Set ctlSystemDateBlock = ctlDayBlock
  93.               blnSystemDateIsShown = True
  94.             Else
  95.               ctlDayBlock.ForeColor = 8388608       ' txt colour
  96.               If astrCalendarBlocksStatus(bytBlockCounter) = "Cancelled" Then
  97.                 ctlDayBlock.BackColor = 12632256      'Background if Cancelled
  98.               Else
  99.                 ctlDayBlock.BackColor = 16777215      'Background Main cell colour
  100.               End If
  101.             End If
  102. ...
I didn't see any place that the status was being read in from the Table, so I added the array astrCalendarBlocksStatus to hold them. The array is then used again later when the Background Color is being set. This is just one way of doing it. Another way is to change the array to be that of long and determine the color while the records are being looped.
Nov 7 '16 #4
coming up with error of cant assign to array and stopping code at

Expand|Select|Wrap|Line Numbers
  1. astrCalendarBlocksStatus = Nz(rstEvents![Status], "")
  2.  
  3.  
Status is being taken from each record, as this can change, and there can be multiple events on one day.

status would be from tbl_bookings.staus ??
Nov 7 '16 #5
jforbes
1,107 Expert 1GB
There was a typo for line 53 that has been fixed, it was this:
Expand|Select|Wrap|Line Numbers
  1. astrCalendarBlocksStatus = Nz(rstEvents![Status], "")
it should be this:
Expand|Select|Wrap|Line Numbers
  1. astrCalendarBlocksStatus(bytBlockCounter) = Nz(rstEvents![Status], "")
I have no way to be sure of where the Status is coming from. I don't have a copy of that database and I'm going off information that you are providing.


If you can truly have multiple events on the same day, then how would you like to determine the Background Color? As it stands, the last Event that is encountered in rstEvents for a given day will be the one to determine the Background Color.

Another option, which would be somewhat tricky, is to use a TextBox with .TextFormat of "Rich Text" and set a BackgroundColor for each individual event per day. On the plus side the Rich Text approach would eliminate the need for the new Array and allow the BackgroundColor to be defined in astrCalendarBlocks.
Nov 7 '16 #6
now coming up with a compile error of no 'end select'

i put one in at the bottom and compile error for without next.


i understand sorry, attached now is a lite version of the database, Satus is coming from the tblevents which is where the date and start times etc.. come from.

i was thinking more of changing the text for that event rather than the whole block.

thought changing the block colour for certain days such as bank holidays or weekend etc.. was something i was also thinking of.

I happy to modify when the base of the idea is correct, just have no idea where to start with it all or the best way of doing it. so all help is greatly appreciated.
Attached Files
File Type: zip TSCSC.zip (104.9 KB, 52 views)
Nov 7 '16 #7
jforbes
1,107 Expert 1GB
This is what I came up with, it allows for each appointment to be color coded both the Foreground and Background. I don't know if you need all that flexibility, but it was only a couple lines more of code.



To get this to work, you will need to change the .TextFormat property to "Rich Text" for all 42 TextBoxes. Just select them all and change the property once.

The following code will need to be placed at the Top of the Code for the fdlgEventDetails(frmCalendar):
Expand|Select|Wrap|Line Numbers
  1. Private Const nAppointmentTemplate = "<div><font color={2} style=""BACKGROUND-COLOR:{3}"">[{0}] - {1}</font></div>"
This sets up a constant, a template for the display text.

The following code is the update to make it all work:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PopulateCalendar()
  2. On Error GoTo Err_PopulateCalendar
  3.  
  4. Dim strFirstOfMonth As String, bytFirstWeekdayOfMonth As Byte, bytBlockCounter As Byte
  5. Dim bytBlockDayOfMonth As Byte, lngBlockDate As Long, ctlDayBlock As Control
  6. Dim bytDaysInMonth As Byte, bytEventDayOfMonth As Byte, lngFirstOfMonth As Long
  7. Dim lngLastOfMonth As Long, lngFirstOfNextMonth As Long, lngLastOfPreviousMonth As Long
  8. Dim lngEventDate As Long, bytBlankBlocksBefore As Byte, bytBlankBlocksAfter As Byte
  9. Dim astrCalendarBlocks(1 To 42) As String, db As Database, rstEvents As Recordset
  10. Dim strSelectEvents As String, strEvent As String, strPlatoons As String
  11. Dim intMonth As Integer, intYear As Integer, lngSystemDate As Long  'CFB added 1-25-08
  12. Dim ctlSystemDateBlock As Control, blnSystemDateIsShown As Boolean  'CFB added 1-25-08
  13. Dim strSQL As String    'Added 4/16/2008
  14. Dim blnRetVal
  15. Dim sBackgroundColor As String, sForeColor As String
  16.  
  17. lngSystemDate = Date    'CFB added 1-25-08
  18. intMonth = objCurrentDate.Month
  19. intYear = objCurrentDate.Year
  20. lstEvents.Visible = False
  21. lblEventsOnDate.Visible = False
  22. lblMonth.Caption = MonthAndYear(intMonth, intYear)
  23. strFirstOfMonth = Str(intMonth) & "/1/" & Str(intYear)
  24.   'ADezii
  25.   'NOTE: Will work in the UK (United Kingdom) and other European Nations
  26.   'strFirstOfMonth = "1/" & Str(intMonth) & Str(intYear)
  27. bytFirstWeekdayOfMonth = Weekday(strFirstOfMonth)
  28. lngFirstOfMonth = DateSerial(intYear, intMonth, 1)
  29. lngFirstOfNextMonth = DateSerial(intYear, intMonth + 1, 1)
  30. lngLastOfMonth = lngFirstOfNextMonth - 1
  31. lngLastOfPreviousMonth = lngFirstOfMonth - 1
  32. bytDaysInMonth = lngFirstOfNextMonth - lngFirstOfMonth
  33. bytBlankBlocksBefore = bytFirstWeekdayOfMonth - 1
  34. bytBlankBlocksAfter = 42 - (bytBlankBlocksBefore + bytDaysInMonth)
  35.  
  36. Set db = CurrentDb
  37.  
  38. strSQL = "SELECT * From tblEvents "
  39. 'strSQL = strSQL & "WHERE tblEvents.Status <> 'Cancelled' And tblEvents.[StartDate] Between " & lngFirstOfMonth & " And " & lngLastOfMonth &
  40. strSQL = strSQL & "WHERE tblEvents.[StartDate] Between " & lngFirstOfMonth & " And " & lngLastOfMonth & _
  41.                   " ORDER BY tblEvents.[StartDate];"
  42.  
  43. Set rstEvents = db.OpenRecordset(strSQL)    'Added 4/16/2008
  44.  
  45. Do While Not rstEvents.EOF
  46.  
  47.   ' Determine Background Color
  48.   Select Case Nz(rstEvents![Status], "Tentative")
  49.     Case "Tentative", "Confirmed", "Completed"
  50.       sForeColor = "#000077"
  51.       sBackgroundColor = "#FFFFFF"
  52.     Case "Cancelled"
  53.       sForeColor = "#AA0000"
  54.       sBackgroundColor = "#FFFF00"
  55.     Case Else
  56.       sForeColor = "#000077"
  57.       sBackgroundColor = "#FFFFFF"
  58.   End Select
  59.  
  60.   ' Generate Display Text
  61.   'strEvent = "[" & rstEvents![EventID] & "] - " & rstEvents![EventName]
  62.   strEvent = nAppointmentTemplate
  63.   strEvent = Replace(strEvent, "{0}", Nz(rstEvents![EventID], ""))
  64.   strEvent = Replace(strEvent, "{1}", Nz(rstEvents![EventName], ""))
  65.   strEvent = Replace(strEvent, "{2}", sForeColor)
  66.   strEvent = Replace(strEvent, "{3}", sBackgroundColor)
  67.  
  68.   ' Find Day
  69.   bytEventDayOfMonth = (rstEvents!StartDate - lngLastOfPreviousMonth)
  70.   bytBlockCounter = bytEventDayOfMonth + bytBlankBlocksBefore
  71.  
  72.     If astrCalendarBlocks(bytBlockCounter) <> "" Then
  73.       astrCalendarBlocks(bytBlockCounter) = _
  74.       astrCalendarBlocks(bytBlockCounter) & vbNewLine & strEvent
  75.     Else
  76.       astrCalendarBlocks(bytBlockCounter) = strEvent
  77.     End If
  78.     rstEvents.MoveNext
  79. Loop
  80. ...
Attached Images
File Type: jpg CalendarWithRichText.jpg (62.0 KB, 246 views)
Nov 7 '16 #8
not quite sure where this should be sitting?

you say "The following code will need to be placed at the Top of the Code for the fdlgEventDetails:"

Expand|Select|Wrap|Line Numbers
  1. Private Const nAppointmentTemplate = "<div><font color={2} style=""BACKGROUND-COLOR:{3}"">[{0}] - {1}</font></div>"
is that on click or load or something or???
Nov 8 '16 #9
Found the place for this to sit i have put it at the top of the frm_calendar which then made it work. is that correct?
Nov 8 '16 #10
Thanks jforbes, you have been a massive help.
Nov 8 '16 #11
jforbes
1,107 Expert 1GB
Ahh, yes. The Constant is to be placed at the top of frmCalendar instead of fdlgEventDetails. Glad you figured out what I meant instead of what I posted.
Nov 8 '16 #12
just an addition to this just to make it easier to change the colours etc... if need be, i thought it would be nice to be able to get the colour codes from a table.

tbl_dbcolours

have the colours in there under heading HexValue and the status in object

i was trying
Expand|Select|Wrap|Line Numbers
  1.   Select Case Nz(rstEvents![Status], "Confirmed")
  2.     Case "Confirmed"
  3.       sForeColor = DLookup("[HexValue]", "tbl_dbColours", "[Object]")
  4.       'sForeColor = "#000077"
  5.       'sBackgroundColor = "#FFFFFF"
  6.     Case "Provisional"
  7.       sForeColor = DLookup("[HexValue]", "tbl_dbColours", "[Object]")
  8.       'sForeColor = "#EE4000"
  9.       'sBackgroundColor = "#FFFFFF"
  10.       Case "Offered"
  11.       sForeColor = DLookup("[HexValue]", "tbl_dbColours", "[Object]")
  12.       'sForeColor = "#E3CF57"
  13.       'sBackgroundColor = "#FFFFFF"
  14.     Case "Cancelled"
  15.       sForeColor = DLookup("[HexValue]", "tbl_dbColours", "[Object]")
  16.       'sForeColor = "#A1A1A1"
  17.       'sBackgroundColor = "#FFFF00"
  18.     Case Else
  19.       sForeColor = "#000077"
  20.      'sBackgroundColor = "#FFFFFF"
  21.   End Select
  22.  
but was getting stuck with the last bit with the object in didnt know how to reffernce the case "confirmed" etc...
Nov 15 '16 #13
jforbes
1,107 Expert 1GB
I think your looking for something like this for your criteria:
Expand|Select|Wrap|Line Numbers
  1.    Select Case Nz(rstEvents![Status], "Confirmed")
  2.      Case "Confirmed"
  3.        sForeColor = DLookup("[HexValue]", "tbl_dbColours", "[Object]='" & Nz(rstEvents![Status], "Confirmed") & "'")
  4. ...

Since your going to be using the Status over and over, you might want to put in it in a Variable. It's a best practice, to make the code easier to read and often times speeds up the code:
Expand|Select|Wrap|Line Numbers
  1.    Dim sStatus As String
  2.    sStatus = Nz(rstEvents![Status], "Confirmed")
  3.  
  4.    Select Case sStatus 
  5.      Case "Confirmed"
  6.        sForeColor = DLookup("[HexValue]", "tbl_dbColours", "[Object]='" & sStatus & "'" )
  7. ...
Nov 15 '16 #14
PhilOfWalton
1,430 Expert 1GB
Wouldn't be easier & more flexible to have a table of Statuses
Expand|Select|Wrap|Line Numbers
  1. TblStatus
  2.     StatusID           Autonumber   PK
  3.     Status             Text         Unique
  4.     StatusForeColour   Long
  5.     StatusBackColour   Long
  6.  
  7.  
Then the Combobox on the fdlgEventDetails form becomes a lookup from the table and the status would automatically have the relevant colours available.

Phil
Nov 15 '16 #15
getting an error of

"invalid use of null"

with both?
Nov 15 '16 #16
jforbes
1,107 Expert 1GB
Typically, if you get "Invalid use of Null" and your using a DLookup, it's because the DLookup is not finding a record to return; the Criteria argument can't match a record. You can verify this running the code with a Break Point on the line with the Select Case and then typing the following into the Immediate Window:
Expand|Select|Wrap|Line Numbers
  1. ?DLookup("[HexValue]", "tbl_dbColours", "[Object]='" & sStatus & "'" )
Access will tell you if is returning a Null. If so, start verifying that the value that is in sStatus is truly in the tbl_dbColours.Object. If it's not, then you found your bug.
Nov 15 '16 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: amber | last post by:
Hi there, I'd like to change the colour of my tabs. I can change my background colour of my tab control, but the actual tabs, with the text on them don't change colour. Am I missing something?...
5
by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in...
11
by: Dixie | last post by:
How can I programatically, take some Date/Time fields present in a table in the current database and change their type to text? dixie
1
by: Ben | last post by:
Hi there, I would like to change the text of the ButtonColumn after datagrid binding, depending on the value of a certain field. (eg. Text="Details" for case 1, Text="others' for case 2) Is...
13
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone...
6
by: K Viltersten | last post by:
I have the following button: <asp:LinkButton id="Btn" runat="server" text="Click"> </asp:LinkButton> I have added an action listener in the javascript where I change the text on it:...
1
by: Andy Sauer | last post by:
Hello. I have a database in Access 2002. I have a table where the field "Name" is set as a required field. I have a form that populates that table. When somebody forgets to fill in the Name...
5
markmcgookin
by: markmcgookin | last post by:
Hi folks, I have a WPF Datagrid in a WPF Project Window. I have populated the grid with a datatable, and autogenerated the columns (unfortunately a necessity) and have a requirement to change the...
4
by: hkw9105 | last post by:
Hi, I am trying to change label text on button click, the way label.text = "string" work well before but not in this case. I tried to put this on other method and it work..it is just not working...
1
by: Chantivenus | last post by:
Hi I would like the values or background colour of a field to show me when there is no entry. For instance if there is a time entered it is red and if nothing then white. If anyone can help please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.