Conditional Formatting Of Carried Forward Values

sal

Registered User.
Local time
Today, 08:32
Joined
Oct 25, 2009
Messages
52
I have a snippet of code (below) that carries values in a form forward during data entry. These values appear in the form on the New record before the record is actually written and I would like them to be red instead of black so the user can easily see that they are on a new record as opposed to a written one.

The following works, sort of, but the red formatting remains for the written values of the carried over records after the record is written. So entering several records then going back to the entered records, the carried forward values are still red.

I would like those values to be black once they are actually written to the record, but red when floating as default values in the unwritten (New) record state.

Private Sub Form_AfterUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "CarryForward" Then
ctl.DefaultValue = """" & ctl.Value & """"
ctl.ForeColor = vbRed
End If
Next ctl
End Sub


How might I modify this to only show the carried over default values in the new record as red but the written values as black?
 
You need two Event Procedures. One already you have and needs little change as below:

Code:
Private Sub Form_AfterUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
      If ctl.Tag = "CarryForward" Then
          ctl.DefaultValue = """" & ctl.Value & """"
           ctl.ForeColor = vbBlack
      End If
Next ctl
End Sub

Next procedure is Form_Current() Event Procedure:

Code:
Private Sub Form_Current()
Dim ctl As Control
If Me.NewRecord then
     For Each ctl In Me.Controls
         If ctl.Tag = "CarryForward" Then
               ctl.ForeColor = vbRed
         End If
     Next
End If

End Sub
 
Thank you but this results in all of the fields with the Carry Forward tag being changed to red for all records. I am trying to just change the floating text in the New Record to red.

My original approach seems unworkable so I am now trying to use the New Record property:

Private Sub Form_Current()
Me.TabCtl141.Enabled = Not Me.NewRecord
Me.SGS_Count_Data_subform.Enabled = Not Me.NewRecord
NewRecordMark Forms![SGS App Form]
End Sub

Private Sub NewRecordMark(frm As Form)
Dim intnewrec As Integer
Dim ctl As Control
intnewrec = frm.NewRecord
If intnewrec = True Then
For Each ctl In Me.Controls
If ctl.Tag = "CarryForward" Then
ctl.ForeColor = vbRed
End If
Next ctl
End If
End Sub

But the floating text on the new record is not red.

I think the problem may be that the fact that the controls I am referencing are on the subform of [SGS App Form]. I tried referencing the subform like this, Forms![SGS App Form]![SGS Survey Form]

but I get a type mismatch error.
 

Users who are viewing this thread

Back
Top Bottom