Full Version: Color txt box
UtterAccess Forums > Microsoft® Access > Access Forms
oxicottin
Hello, I have a calendar thats a continious form that shows data for a day data was entered. I wanted to color the text box if the data was a certain code like EA, would be yellow UA would be pink and so on but I have several variations so conditional formating wouldnt work I also wanted to color todays date. Here is some of the dB so you get an understanding of what I wanted to do. Thanks
oxicottin
Why wont the code Im trying work? I dont care about coloring the current day just coloring the diferent attendanceCodes is my concern.
I have tried the code below and am still getting Runtime Error '3075' Extra) in the query expression. here is the code I tried.Thanks!
CODE
Public Sub SetCalendar()
   Dim StrgSQL As String
   Dim rst As Recordset
   Dim Bclr As Long, Fclr As Long
   Dim iRed As Integer, iGreen As Integer, iBlue As Integer
   Dim i As Integer, AbsentReason As String
  
  
    StrgSQL = "SELECT * FROM tblInput WHERE UserID=" & CLng(Me.cboUser.Column(0)) & _
             " AND Format([InputDate],'yyyy')=" & Me.txtBxYear & ");"
   Set rst = CurrentDb.OpenRecordset(StrgSQL, dbOpenDynaset)
  
   If rst.RecordCount = 0 Then GoTo Exit_SetCalendar
  
   With rst
      .MoveLast: .MoveFirst
      Do Until .EOF
        AbsentReason = Nz(!AttendanceCode, "")
nbsp;       Select Case !AttendanceCode
           Case "V"
              Bclr = 438366: Fclr = 0
           Case "PD"
              Bclr = 16711680: Fclr = 16777215
           Case "UH"
              Bclr = 16633344: Fclr = 0
           Case "ET"
              Bclr = 8421504: Fclr = 16777215
           Case "EA"
              Bclr = 65535: Fclr = 0
           Case "WH"
              Bclr = 16777164: Fclr = 0
           Case "UA"
              Bclr = 255: Fclr = 16777215
           Case "UT"
              Bclr = 16711935: Fclr = 16777215
           Case "ELE"
              Bclr = 65535: Fclr = 0
           Case "PC"
              Bclr = 26367: Fclr = 16777215
           Case "DL"
              Bclr = 16776960: Fclr = 0
           Case "ML"
              Bclr = 128: Fclr = 16777215
           Case "FL"
              Bclr = 65280: Fclr = 0
           Case "PL"
              Bclr = 10092543: Fclr = 0
           Case "JD"
              Bclr = 52479: Fclr = 0
           Case "FL"
              Bclr = 13408767: Fclr = 0
        End Select
        For i = 1 To 31
           If Me.Controls("Text" & i) = AbsentReason Then
           End If
        Next i
        Bclr = vbWhite: Fclr = vbBlue: AbsentReason = ""
        .MoveNext
      Loop
   End With
Exit_SetCalendar:
   rst.Close
   Set rst = Nothing
End Sub
ALaRiva
The error is pretty self explanatory. You have an extra ')' in your SQL Code
!--c1-->
CODE
StrgSQL = "SELECT * FROM tblInput WHERE UserID=" & CLng(Me.cboUser.Column(0)) & _            
" AND Format([InputDate],'yyyy')=" & Me.txtBxYear & ");"

Should be:
CODE
StrgSQL = "SELECT * FROM tblInput WHERE UserID=" & CLng(Me.cboUser.Column(0)) & _            
" AND Format([InputDate],'yyyy')=" & Me.txtBxYear & ";"
oxicottin
that worked but it still isnt coloring my boxes? What am i missiing....


Thanks,
Chad
Edited by: oxicottin on Wed Sep 3 21:42:29 EDT 2008.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.