Stuart McLachlan
stuart at lexacorp.com.pg
Sun Feb 8 22:14:59 CST 2009
Thanks for the various suggestions, they got me thinking. In the end, it was Max's mention of Column() that gave me the hint I needed. When I thought about it some more, I didn't need to hit the lookup tables at all, all the old info was already available in the two columns in each Combobox's List. I just needed to iterate through the list, looking for a match in Column(1) and pulling the relevant description from Column(0), For anyone who might be interested, here's the complete logging procedure. Private Sub Form_BeforeUpdate(Cancel As Integer) Dim ctl As Control Dim strOldValue As String Dim lngLoop As Long Dim strSQL As String strchanges = "" For Each ctl In Me.Controls Select Case Left(ctl.Name, 3) Case "cbo" If Nz(ctl.Value, "") <> Nz(ctl.OldValue, "") Then If Nz(ctl.OldValue, 0) = 0 Then strOldValue = "BLANK" Else For lngLoop = 0 To ctl.ListCount - 1 If CLng(ctl.Column(1, lngLoop)) = ctl.OldValue Then strOldValue = ctl.Column(0, lngLoop) Exit For End If Next End If strchanges = strchanges _ & Mid$(ctl.Name, 4, Len(ctl.Name) - 5) _ & " changed from """ _ & strOldValue _ & """-to-""" _ & Nz(ctl.Column(0), "BLANK") & """" & vbCrLf End If Case "txt" If Nz(ctl.Value, "") <> Nz(ctl.OldValue, "") Then strchanges = strchanges & Mid$(ctl.Name, 4) _ & " changed from """ _ & Nz(ctl.OldValue, "BLANK") _ & """-to-""" _ & Nz(ctl.Value, "BLANK") & """" & vbCrLf End If Case Else End Select Next If strchanges > "" Then strchanges = Replace(strchanges, "'", "''") strSQL = "Insert into tblDiary " _ & " (DTG,TenderID,creator,comments)" _ & " values (Now()," & TenderID & ",'" _ & GetUserName() & "','" & strchanges & "')" CurrentDb.Execute strSQL End If End Sub