History of form data

J

John

Hi

I have a orders form with a sub form of transactions. I need to keep
historical snapshot of changes. I have managed to take snapshot of main form
in a string as below;

St=""
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If (IsNull(ctl.OldValue) And Not IsNull(ctl.Value)) Or
(IsNull(ctl.Value) And Not IsNull(ctl.OldValue)) Then
St = St & ctl.Name & "=" & ctl.Value & vbCrLf & vbCrLf
ElseIf ctl.OldValue <> ctl.Value Then
St = St & ctl.Name & "=" & ctl.Value & vbCrLf & vbCrLf
End If
End If
Next ctl

How can I take such a snapshot of the sub form data?

Thanks

Regards
 
D

Douglas J. Steele

Try something like:

Dim ctl As Control
Dim subctl As Control
Dim St as String

St = vbNullString
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If (ctl.OldValue & vbNullString) <> _
(ctl.Value & vbNullString) Then
St = St & ctl.Name & "=" & ctl.Value & vbCrLf & vbCrLf
End If
ElseIf ctlControlType = acSubForm Then
For Each subctl In ctl.Controls
If subctl.ControlType = acTextBox Then
If (subctl.OldValue & vbNullString) <> _
(subctl.Value & vbNullString) Then
St = St & ctl.Name & "." & subctl.Name & _
"=" & subctl.Value & vbCrLf & vbCrLf
End If
End If
Next subctl
End If
Next ctl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top