Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AppendChunk Problem 2

Status
Not open for further replies.

krispi

MIS
May 16, 2002
281
GB
Can anyone help me with what I suspect is a very simple problem...as you'll see, I am very much a novice...?

I have a command button on my form (FormCases1). Also on the form is a memo field (TCCaseDetails). What I want to happen on button press is for the UserName and current date/time to appear on the next free line of the memo field, then for the cursor to position itself one character width to the right of this point for the user to begin typing notes. On searching the help file it appears that the AppendChunk function is the best way of doing this and I have had a go at some code (see below). The problems are:
1: On pressing the button, the information appends to the first record in the set, not the current record, which is what I want.
2: I can't work out how to position the cursor once the operation has completed.

Here's the code, if anyone can come up with the necessary changes/additions, I'll be very grateful.

Sub CasesMemo()

Dim dbs As Database
Dim rst As Recordset
Dim fldNotes As Field
Dim lngSize As Long
Dim strChunk As String

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("QueryIntExtCases")
Set fldNotes = rst!TCCaseDetails
If IsNull(fldNotes.Value) Then
strChunk = CurrentUser & " " & Now
With rst
.Edit
!TCCaseDetails = strChunk
.Update
End With
Else
lngSize = Len(fldNotes)
strChunk = fldNotes.GetChunk(1, lngSize)
strChunk = strChunk & " " & CurrentUser & " " & Now
With rst
.Edit
!TCCaseDetails.AppendChunk strChunk
.Update
End With
End If
End Sub

Thanks
Chris
 
Your code above is not necessary as you appear to be trying to update the table fields rather than just place your cursor and update the form object which is what you described. Since your form object is bound to the underlying query/table as a recordsource you do not need to perform any update of a recordset.

Put this code behind the button in the OnClick event procedure:
Me![TCCaseDetails].SetFocus
If IsNull(me![TCCaseDetails]) Then
Me![TCCaseDetails] = CurrentUser & " " & Now & ": "
Else
Me![TCCaseDetails] = Me![TCCaseDetails] & vbCrLf & CurrentUser & " " & Now & ": "
End If
Me![TCCaseDetails].SelLength = 0
Me![TCCaseDetails].SelStart = Len(Me![TCCaseDetails]) + 1


You tables data field will be updated upon a save of the record being displayed so it is only necessary to deal with the form field object. I hope I got the form object name correct. See if this will do the job for you.

Bob Scriver



 
Thanks Bob that works great. Have a star!!
 
Thanks you. I am glad this works for you.

Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top