By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,454 Members | 2,633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,454 IT Pros & Developers. It's quick & easy.

Change Font color of text string.

P: 78
Hello All,

I have a DB that shows information generated on a form setup to look like a calendar. I am working with Windows 2000 and Access 2000.

Expand|Select|Wrap|Line Numbers
  1. Public Sub PutInData()
  2. On Error GoTo Err_PutIndata
  3. Dim sql As String
  4. Dim f As Form
  5. Dim db As DAO.Database
  6. Dim rs As DAO.Recordset
  7. Dim rsHoliday As DAO.Recordset
  8. Dim sqlHoliday As String
  9. Dim MyDate As Date
  10. Dim i As Integer
  11. Dim strShiftDetails As String
  12.  
  13. Set f = Forms!frmCalendar
  14.  
  15. For i = 1 To 37
  16.   f("text" & i) = Null
  17. Next i
  18.  
  19. sql = "SELECT * FROM [qryShifts] WHERE ((MONTH(ShiftDetailDate) = " & _
  20.        f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) " & _
  21.        "ORDER BY tblShiftDetail.ShiftDetailDate, tblEmployee.EmployeeFirstName;"
  22. sqlHoliday = "SELECT * FROM [tblHoliday] WHERE ((MONTH(ShiftDetailDate) = " & _
  23.               f!month & " AND YEAR(ShiftDetailDate) = " & f!year & ")) " & _
  24.               "ORDER BY [tblHoliday].[ShiftDetailDate];"
  25.  
  26. Set db = CurrentDb()
  27. Set rs = db.OpenRecordset(sql)
  28. Set rsHoliday = db.OpenRecordset(sqlHoliday)
  29.  
  30. If rs.RecordCount > 0 Then
  31.   For i = 1 To 37
  32.     If IsDate(f("date" & i)) Then
  33.     MyDate = Format((f("date" & i)), "mm/dd/yyyy")
  34.       Do While Not rs.EOF
  35.         If rs![ShiftDetailDate] = MyDate Then
  36.             If rs![ShiftDetailOnCall] = True Then
  37.                 strShiftDetails = strShiftDetails & Left(rs!EmployeeFirstName, 1) & Left(rs!EmployeeLastName, 1) & " " & _
  38.                                     rs!ShiftStartTime & "-" & rs!ShiftEndTime & " On Call" & vbCrLf
  39.             Else
  40.                 strShiftDetails = strShiftDetails & Left(rs!EmployeeFirstName, 1) & Left(rs!EmployeeLastName, 1) & " " & _
  41.                                     rs!ShiftStartTime & "-" & rs!ShiftEndTime & vbCrLf
  42.             End If
  43.         End If
  44.         rs.MoveNext
  45.       Loop
  46.       If Len(strShiftDetails) > 0 Then
  47.         f("text" & i) = Left$(strShiftDetails, Len(strShiftDetails) - 2)      'Strip vbCrLf
  48.       End If
  49.       strShiftDetails = ""      'Reset
  50.       rs.MoveFirst
  51.       rsHoliday.FindFirst "ShiftDetailDate = #" & MyDate & "#"
  52.         If Not rsHoliday.NoMatch Then
  53.           strShiftDetails = rsHoliday![Description] & " - Help Desk Off!!"
  54.           f("text" & i) = strShiftDetails
  55.           strShiftDetails = ""
  56.         End If
  57.     End If
  58.   Next i
  59. End If
  60.  
  61. rsHoliday.Close
  62. Set rsHoliday = Nothing
  63. rs.Close
  64. Set rs = Nothing
  65. Set db = Nothing
  66.  
  67. Exit_PutIndata:
  68.   Exit Sub
  69.  
  70. Err_PutIndata:
  71.   MsgBox Err.Description, vbExclamation, "Error in PutIndata()"
  72.   Resume Exit_PutIndata
  73. End Sub
  74.  
What I want to do is if [shiftdetailoncall] = True then change the font color to RED for information stored (Rather then putting On Call text in place). However I need to have the rest of the text left Black.

Note: It does not have to be a color change, but I need someway to visually set it appart from the rest.

Information is being viewed in a textbox on the form, then opened in a report.

Can anyone help with achieving this? I am at a complete loss. Can this even be done?

Thank you in advance for any advice on this.

Nick
May 9 '08 #1
Share this Question
Share on Google+
2 Replies


missinglinq
Expert 2.5K+
P: 3,532
"What I want to do is if [shiftdetailoncall] = True then change the font color to RED for information stored"

I'm not at all sure what you mean by this. Formatting is never done for information stored but rather forinformation displayed!And your code is way too complex for me to understand remotely.

Any formatting will have to done thru your form. If the form is datasheet or continuous the formatting will have to be done thru Conditional Formatting from the menu, otherwise it may also be done thru code in the Form's OnCurrent event.

Linq ;0)>
May 9 '08 #2

ADezii
Expert 5K+
P: 8,597
Nick, if I interpret your request correctly, this cannot be done. Your request would entail different formatting (ForeColor, Underline, Italic, etc.) for individual lines in a Standard Text Box Control, depending on whether or not the [ShiftDetailOnCall] Field was True. To the best of my knowledge, this cannot be done in a Standard Text Box Control. You can, however, specify unique Text within the strShiftDetails Variable to indicate this condition. This is, however, what you basically have already:
Expand|Select|Wrap|Line Numbers
  1. If rs![ShiftDetailOnCall] = True Then
  2.   '(C) - at end of String indicates On Call Status
  3.   strShiftDetails = strShiftDetails & Left(rs!EmployeeFirstName, 1) & Left(rs!EmployeeLastName, 1) & " " & _
  4.                                     rs!ShiftStartTime & "-" & rs!ShiftEndTime & " (C)" & vbCrLf
  5. Else
  6.   strShiftDetails = strShiftDetails & Left(rs!EmployeeFirstName, 1) & Left(rs!EmployeeLastName, 1) & " " & _
  7.                                     rs!ShiftStartTime & "-" & rs!ShiftEndTime & vbCrLf
  8. End If
NOTE: If there was only a Single Shift per day, this could be done since the Formatting would apply to the entire Control.
May 9 '08 #3

Post your reply

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