Text Box Message In IF Statement

gracm25

Registered User.
Local time
Today, 12:03
Joined
Dec 6, 2007
Messages
31
When I try to run the following code, I get a run-time error 2448 that reads, "You can't assign a value to this object." This applies to the message that reads "APPLY SRT'S!!. I don't know where to place this text in order for it to be visible when REPAIR_TYPE is blank. The message will be printing in a text box. Any suggestions?

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim dblInterval As Double
Dim lngGreen As Long

dblInterval = CDbl(dateTimeEnd - dateTimeStart)

lngGreen = RGB(0, 128, 64)

Me!ElapsedTimeString.ForeColor = vbBlack
Me!ElapsedTimeString.FontBold = False
Me!ElapsedTimeString.FontUnderline = False
Me!TimeRemaining.ForeColor = vbBlack
Me!TimeRemaining.FontBold = False
Me!TimeRemaining.FontUnderline = False

If REPAIR_TYPE = "MINOR" Then
If dblInterval < 1 Then
Me!ElapsedTimeString.ForeColor = vbRed
Me!ElapsedTimeString.FontBold = True
Me!ElapsedTimeString.FontUnderline = True
Me!TimeRemaining.ForeColor = vbRed
Me!TimeRemaining.FontBold = True
Me!TimeRemaining.FontUnderline = True
End If
ElseIf REPAIR_TYPE = "MAJOR" Then
If dblInterval < 1 Then
Me!ElapsedTimeString.ForeColor = vbRed
Me!ElapsedTimeString.FontBold = True
Me!ElapsedTimeString.FontUnderline = True
Me!TimeRemaining.ForeColor = vbRed
Me!TimeRemaining.FontBold = True
Me!TimeRemaining.FontUnderline = True
ElseIf dblInterval >= 1 And dblInterval < 3 Then
Me!ElapsedTimeString.ForeColor = vbBlue
Me!ElapsedTimeString.FontBold = True
Me!ElapsedTimeString.FontUnderline = True
Me!TimeRemaining.ForeColor = vbBlue
Me!TimeRemaining.FontBold = True
Me!TimeRemaining.FontUnderline = True
Else
' Add something here for when "MAJOR", dblInterval >= 3
Me!ElapsedTimeString.ForeColor = vbBlack
Me!ElapsedTimeString.FontBold = False
Me!ElapsedTimeString.FontUnderline = False
Me!TimeRemaining.ForeColor = vbBlack
Me!TimeRemaining.FontBold = False
Me!TimeRemaining.FontUnderline = False
End If
Else
Me!ElapsedTimeString.ForeColor = lngGreen
Me!ElapsedTimeString.FontBold = True
Me!ElapsedTimeString.FontUnderline = True
Me!TimeRemaining.ForeColor = lngGreen
Me!TimeRemaining.FontBold = True
Me!TimeRemaining.FontUnderline = True
Me!TimeRemaining = "APPLY SRT's!!"
End If

End Sub
 
Detail_Format is a report event, and I'm going to guess that TimeRemaining is a bound control. Assuming that's correct, you cannot write to an object that is bound to a table or query in report view. You'll have to make TimeRemaining a calculated field (which will make it unbound), at which point you can change its contents. You can do the calculation in a query or in the Detail_Format event. The easiest way to do this will be to write a function that does what you want and then set the value of an unbound control to that function.

This is somewhat pseudo-coded, but you should get where I'm going with it.

Code:
Function CalcTimeRemaining() As String

    Dim dblInterval As Double
    Dim lngGreen As Long

    dblInterval = CDbl(dateTimeEnd - dateTimeStart)
    lngGreen = RGB(0, 128, 64)

    Me!ElapsedTimeString.ForeColor = vbBlack
    Me!ElapsedTimeString.FontBold = False
    Me!ElapsedTimeString.FontUnderline = False
    Me!TimeRemaining.ForeColor = vbBlack
    Me!TimeRemaining.FontBold = False
    Me!TimeRemaining.FontUnderline = False

    Select Case REPAIR_TYPE
        Case "Minor"
            If dblInterval < 1 Then
                Me!ElapsedTimeString.ForeColor = vbRed
                Me!ElapsedTimeString.FontBold = True
                Me!ElapsedTimeString.FontUnderline = True
                Me!TimeRemaining.ForeColor = vbRed
                Me!TimeRemaining.FontBold = True
                Me!TimeRemaining.FontUnderline = True
            End If
        Case "MAJOR"
            Select Case dblInterval
                Case <1		 
                    Me!ElapsedTimeString.ForeColor = vbRed
                    Me!ElapsedTimeString.FontBold = True
                    Me!ElapsedTimeString.FontUnderline = True
                    Me!TimeRemaining.ForeColor = vbRed
                    Me!TimeRemaining.FontBold = True
                    Me!TimeRemaining.FontUnderline = True
                Case >=1 And <3
                    Me!ElapsedTimeString.ForeColor = vbBlue
                    Me!ElapsedTimeString.FontBold = True
                    Me!ElapsedTimeString.FontUnderline = True
                    Me!TimeRemaining.ForeColor = vbBlue
                    Me!TimeRemaining.FontBold = True
                    Me!TimeRemaining.FontUnderline = True
                Case >= 3
                    ' Add something here for when "MAJOR", dblInterval >= 3
                Case Else
            End Select
        Case Else
            Me!ElapsedTimeString.ForeColor = lngGreen
            Me!ElapsedTimeString.FontBold = True
            Me!ElapsedTimeString.FontUnderline = True
            Me!TimeRemaining.ForeColor = lngGreen
            Me!TimeRemaining.FontBold = True
            Me!TimeRemaining.FontUnderline = True
            [COLOR="Red"]CalcTimeRemaining[/COLOR] = "APPLY SRT's!!"
    End Select

End Function

From here, you make a new textbox on your report, name it something obvious (txtCalcTimeRemaining) and you set it's ControlSource to "=CalcTimeRemaining".

It's not an exact answer and you may end up having to pass a few parameters to the function (I don't have it setup for that, but it's easy to do), but there's enough here to where you should be able to move forward.
 

Users who are viewing this thread

Back
Top Bottom