Cursor reset to start position in a textbox on OnTimer DoCmd.Save

hellind

Registered User.
Local time
Tomorrow, 05:56
Joined
Nov 17, 2008
Messages
21
I have OnTimer set to 60 seconds to run Docmd.Save.

When the user is typing on the textbox entering information, on the 60th second the forms save, and the cursor position reset to the start of the textbox.

It's a nuisance that repeats every 60 seconds. How do I prevent the cursor in a textbox resetting to the start position? How do I make the cursor position in the textbox stay where it was, i.e. where the user is still typing.
 
That would make my cursor position to zero. But I want to prevent that, I want the cursor to be where the user is still typing.
 
First off, I have to believe that you think that DoCmd.Save is actually saving the data in your record, which it isn't! This command saves changes in the design of objects, in this case, any changes made in the design of the form.

To save your record and its data, you'd have to use

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty Then Me.Dirty = False

Secondly, one has to ask why you feel the need to run Save every 60 seconds. This is a most unusual thing to do.
 
That would make my cursor position to zero. But I want to prevent that, I want the cursor to be where the user is still typing.

Sorry my bad, I misread your OP.

However if you combine my previous code with the Len() function it will do what you want. It should look something like;

Code:
Me.TextBoxName.SelStart = Len(Me.TextBoxName)

Caveat; I've not test this so it may require some tweaking, it should however set you on the right path.
 
Thanks for the help. But you are assuming users are always typing at the end of the text-box. What if they are making any changes between the text which they often do. And then when auto-save is activated, the cursor reset to the start position and they misplace what they are typing.



@missinglinq, what do you suggest other than the auto-save at 60 seconds. It was requested by my users because they did not want anything they typed to be lost.
 
I'd tell them having an auto-save feature is causing the behavior they apparently object to, as listed in your original post and is slowing down everything they do, by chewing up resources, which it is. I'd also tell them this is not a word processing program, it's a database. The fact is, with using DoCmd.Save, they've been using the database, for however long, without saving their data every minute; has it caused problems so far?

After changing DoCmd.Save to one of the two pieces of code I gave you, which does save the data, does the problem persist?

Once you get the program saving data every 60 seconds, if you have any validation code in the Form_BeforeUpdate event, it will fire every minute, also, if data is missing, and cause more delays.

Lastly, about John's code; he's right, it does need a little tweaking. Anytiem you set something like this using SelStart and Len() you have only run the code if there is some data in the control, or Len being Null will pop an error:
Code:
If Not IsNull(Me.TextBoxName) Then
 Me.TextBoxName.SelStart = Len(Me.TextBoxName) 
End If
 
SelStart returns or sets the starting point of text selected; indicates the position of the insertion point if no text is selected. See here and here for more details.

As part of the AutoSave procedure you could try using the SelStart function to record the cursor position before the Save is started and then after the save has finished use it to reposition the cursor.
 

Users who are viewing this thread

Back
Top Bottom