My thanks to
Bob Bedell for sterling help - a really good outcome!
Here's a summary for anyone that wants to use it.
This allows the user to input free form comments and then have them appended to a 'journal'.
============================
[u]Pre-requisites:</u>
- tblRisk (including ID, Journal)
- frmRisk (including txtID, txtComment, txtJournal, cmdJournal)
[u]Code:</u>
Private Sub cmdJournal_Click()
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim datToday As Date
Dim strSQL As String
Set db = CurrentDb()
'Retrieve primary key value of current record from hidden textbox
'control bound to the recordsource ID field. txtID is hidden
strSQL = "SELECT Journal FROM tblRisks Where ID = " & Me.txtID
'Open updateable recordset using SQL string as source argument.
'Recordset contains only the current record
Set rec = db.OpenRecordset(strSQL, dbOpenDynaset)
datToday = Date
'copy the current record to the copy buffer
rec.Edit
'make changes to the current record in the copy buffer
If Not IsNull(rec("Journal")) Then
rec("Journal") = rec("Journal") & vbCrLf & vbLf & "(" & datToday & ") " & Me.txtComment
Else
rec("Journal") = "(" & datToday & ") " & Me.txtComment
End If
'save the contents of the copy buffer to disk
rec.Update
On Error Resume Next
'display new Journal value
Me.txtJournal = rec("Journal")
'clear Comments textbox
Me.txtComment = vbNullString
End Sub
Private Sub txtComment_Enter()
'This routine simply ensures that the current record's primary key value
'gets written to the table so that the cmdJournal_Click event can use it.
If (Me.NewRecord) And (Me.Dirty) Then
DoCmd.RunCommand acCmdSaveRecord
End If
End Sub
=====================
Bob,
I'm happy to email you a sample of the Risk Register so you can see the end result - send me your address if you like.
All the best,
Tony Adams
(Melbourne, Australia)
[email protected]