Excellent. I got it working for the OnCurrent event of my subform,
frmDailyData. (Controls with a tag of "**" need to be disabled if
DailyDate is Null, so by parsing out multiple tag properties the code
works for controls with more than one tag.)
However, I'm also trying to use the split function in a global module.
The goal is to carryover data from the previous record only for
controls with a tag property of "carryover". (This feature is the
reason for the second tag.) On the BeforeInsert Event of my subform,
frmDailyData, I have this:
Private Sub Form_BeforeInsert(Cancel As Integer)
Call CarryOver(Me)
End Sub
And in a separate module, I've placed the code at the end of this
thread.
Basically, I tried to wrap the carryover code between an ... If
strMyTag(intI) = "carryover" Then ... statement. But I obviously have
something wrong because data is carried over for all controls on the
subform (whether they have no tags, a tag of "**", or a tag of " * ;
carryover ". It's ignoring the If Then condition entirely.
Thanks for your continued help!
###
Sub CarryOver(frm As Form)
On Error GoTo Err_CarryOver
' CarryOver code from
http://allenbrowne.com/ser-24a.html
Dim rst As DAO.Recordset
Dim ctl As Control
Dim i As Integer
Dim strMyTag() As String
Dim intI As Integer
Set rst = frm.RecordsetClone
For Each ctl In frm
If Len(ctl.Tag & vbNullString) > 0 Then
strMyTag = Split(ctl.Tag, ";")
For intI = 0 To UBound(strMyTag)
If strMyTag(intI) = "carryover" Then
If rst.RecordCount > 0 Then
rst.MoveLast
For i = 0 To frm.Count - 1
Set ctl = frm(i)
If TypeOf ctl Is TextBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
ElseIf TypeOf ctl Is ComboBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
ElseIf TypeOf ctl Is CheckBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
End If
Next
End If
End If
Next intI
End If
Next
Set ctl = Nothing
Exit_CarryOver:
Set rst = Nothing
Exit Sub
Err_CarryOver:
Select Case Err
Case 2448 'Cannot assign a value
Debug.Print "Value cannot be assigned to " & ctl.Name
Resume Next
Case 3265 'Name not found in this collection.
Debug.Print "No matching field name found for " & ctl.Name
Resume Next
Case Else
MsgBox "Carry-over values were not assigned, from " & ctl.Name
& _
". Error #" & Err.Number & ": " & Err.Description,
vbExclamation, "CarryOver()"
Resume Exit_CarryOver
End Select
End Sub