In Chapt 6 page 114.
I've created the "lstHistory" form, but I don't know how to call the following code or where/how to apply it on the form.
I'd like the exact syntax if possible? Any assistance is greatly appreciated. Thanks in advance
Code:
Private Sub ShowColumnHistory(strTableName As String, strFieldName As String)
'History data is in this format:
'[Version: Date Time ] History Data
Const VERSION_PREFIX As String = "[Version: "
Dim strHistory As String
Dim strHistoryItem As String
Dim astrHistory() As String
Dim lngCounter As Long
Dim datDate As Date
Dim datTime As Date
Dim strData As String
'Get the column history
strHistory = Application.ColumnHistory(strTableName, strFieldName, "")
'Make sure there is history data
If Len(strHistory) > 0 Then
'Parse the column history into separate items.
'Each item in the history is separated by a vbCrLf, but
'if there are carriage-returns in the memo field data
'you will get unexpected results. Split on the VERSION string
'in the history data.
astrHistory = Split(strHistory, VERSION_PREFIX)
'Adding these lines ensures this code works regardless of
'how the control is configured on the form
Me.lstHistory.RowSourceType = "Value List"
Me.lstHistory.ColumnCount = 3
Me.lstHistory.ColumnHeads = True
'Add column headings to the list box
Me.lstHistory.AddItem "Date;Time;History"
'Enumerate the history data in reverse
'to fill the list box in descending order
For lngCounter = UBound(astrHistory) To LBound(astrHistory) Step -1
'Parse the history data
strHistoryItem = astrHistory(lngCounter)
If Len(strHistoryItem) > 0 Then
'Parse the date from the history data.
'This example parse the default US date format.
datDate = CDate(Left(strHistoryItem, InStr(strHistoryItem, " ") - 1))
strHistoryItem = Mid(strHistoryItem, InStr(strHistoryItem, " ") + 1)
'Parse the time from the history data
datTime = CDate(Left(strHistoryItem, InStr(strHistoryItem, " ] ") - 1))
strHistoryItem = Mid(strHistoryItem, InStr(strHistoryItem, " ] ") + 3)
'Add the history item to the list box.
Me.lstHistory.AddItem datDate & ";" & datTime & ";" & strHistoryItem
End If
Next
Else
MsgBox "There is no history information for the specified field"
End If
End Sub