OnChange - txtbox keeps pace with other txtbox

craigachan

Registered User.
Local time
Today, 00:15
Joined
Nov 9, 2007
Messages
285
I'm having trouble understanding what is going on.

I have:
Form - TestForm

Fields: Note, PreNote, PostNote, and cursorposition

I have the following code:
Code:
Option Compare Database
Option Explicit
Private Sub cmdClear_Click()
    cursorposition = Null
    PreNote = Null
    PostNote = Null
    Note = Null
 
End Sub
Private Sub Note_Change()
    Dim cp As Integer
    cp = Me.Note.SelStart
 
    Me.cursorposition = Me.Note.SelStart
    Me.PreNote = Mid(Me.Note, 1, cp)
    Me.PostNote = Mid(Me.Note, cp + 1)
 
 
End Sub
Private Sub Note_GotFocus()
    Dim cp As Integer
    cp = Me.Note.SelStart
 
    Me.cursorposition = Me.Note.SelStart
End Sub

When I type in new text to Me.Note, I notice that Me.Cursorposition keeps pace with my cursor. But PreNote and PostNote do not update until I move out of the field and then go back to Me.Note and then add something.

I'm trying to get Me.PreNote and Me.PostNote to update each time I add a character to Me.Note. I'll use the results of Pre and Post to insert text in Me.Note later.

Can anyone tell me what is happening and how I can make this work the way I want? Thank you.
 
Until you leave the control and the control is updated, the changes are taking place in the control's .Text property and not the .Value property. Try:
Me.PreNote = Mid(Me.Note.Text, 1, cp)
Me.PostNote = Mid(Me.Note.Text, cp + 1)
 
I used the code you did but this does not keep pace. I would like the PreNote and PostNote field to actually mirror their individual parts in real time. Is this possible?
 
I'm not sure what you mean but try putting a DoEvents in before you leave the Sub.
 
I'm not sure how to do this. But doesn't DoEvents cause other problems? Can you give me an example in my case?
 
Actually I stand corrected. The code that you suggested does work, that is copying the .text rather than copying the field. Thank you. I used:

Me.PreNote = Mid(Me.Note.text, 1 , cp)

It worked like a charm. Thanks a million.
 
DoEvents simply relenquishes the cpu to other tasks within Access.
Code:
Me.PreNote = Mid(Me.Note.Text, 1, cp)
Me.PostNote = Mid(Me.Note.Text, cp + 1)
DoEvents
I suspect you are simply a victim of the internal priority scheme of Access. If it causes problems then remove it.
 

Users who are viewing this thread

Back
Top Bottom