Link to home
Start Free TrialLog in
Avatar of cazink
cazinkFlag for United States of America

asked on

why in the code window does the cursor now move on its own

This has happened once before in another database and I erased it to solve the problem and it was with an earlier version.
In the vba code window of Access, when I try to edit text, if I open up a line of code the text will turn red and then may close the gap on its own and if I try to type some text it may rearrange this by a character or two. It almost sounds like a virus attack but I do not think so. I just think it is something that just got out of wack somewhere with the intellisence. This is almost hard to describe what is happening, but if it happened to you, you would know just what I am talking about
HELP
Avatar of omgang
omgang
Flag of United States of America image

Can you post a screen shot of the VBE with the red text please?

OM Gang
Avatar of cazink

ASKER

Not really it is intermittent now. In the past when this started it was peculiar to a certain database and got worse as time when on. Lets say I have this line of text Me.txtTextBox and I want to change the code and I have renamed the control name. When I place the cursor in the line at the period and hit the space bar the line now looks like this
Me. txtTextBox then the letters turn red as if an error had occurred and if I delete back to the period and start to type the letters might rearrange in the first position after the period. Something triggered this and it becomes impossible to do any amount of coding without making mistakes.  
I've never experienced anything like you describe.  The VBE default setting for syntax errors is to highlight to code in red text but this doesn't sound like what you're describing.

OM Gang
Ah, yes, a fun one.

Steps to reproduce this behaviour: create a new form, set the timer interval to 100, create a timer event (with just "DoEvents" for example), and open the form.

Now, VB will be running some code 10 times every second. In order to do that, it will attempt to compile any code in an unknown state. As a side effect, this will terminate the editing of any line, with the usual clean-up: removal of spaces, highlighting of syntax errors, etc. It becomes very weird to try editing VB code.

Annoying... but on the other hand, it's very bad practice to edit your VB code in a live database (if you edit live class modules, you easily run into VB corruption, for example). So you should simply change your habits: create and edit VB code with all objects closed or in design view. Just like with compilable languages.

Cheers!
(°v°)
Avatar of cazink

ASKER

I am not quite sure if your comment is a solution or a way to recreate the same thing happening.
I have been known to edit code while the form is active and not in design mode. Did not realize this is a problem
Will not do this in the future. Is there a solution?
ASKER CERTIFIED SOLUTION
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cazink

ASKER

Not really,
In other words, since I do not have any forms with timer events or timer intervals set or running, then this was not the culprit and it may have been just editing an open form. But to your solution, I did not follow the method of recreating the symptom. An exclamation with a little more detail would be better, since I did not understand where you were going with your example.
Regards,
Charly
If it wasn't a form with a timer event, then this is becoming complicated.

I know that the symptoms you describe are caused by some VB code running. As I tried to explain, VB is continuously checking the syntax to compile the very module you are editing. Normally, you get a syntax check when you leave a line (the highlighting in red), a compilation or pre-compilation when you request it or when you try to run a given function, and then run-time errors. In this "running" mode, you get a continuous syntax check and attempts at compilation.

Since VB is multi-threaded (it isn't as a language, but it is through the event handling of Access), you can have code running in one module while another is open for editing.

The complicated question is then: what portion of your code is running? I have no means of answering that, of course; a timer event was my best bet. It could be a loop, perhaps some quite long operation, with a "DoEvents" here and there. The loop will continue to execute, but without locking the application. At every "DoEvents", all user input would be processed, including the editing of VB code. But then the loop would resume, forcing VB to maximize the compile state of the project, hence the syntax check.

If code is running, you should experience some flicker. The title bar of the VB window should flash "[running]", for example. If you want to stop all code in all modules, you can use the square "reset" button. This doesn't stop timer events (or any other events) to fire, but it stops all the rest and releases all class modules. Can you try that the next time you see the symptoms?

Incidentally, I did show a method to recreate the symptoms, not only for omgang but also for you to see that this can be turned on and off, provided you can identify the code that is running, of course.

(°v°)
harfang, thanks for the detailed information.  As I mentioned, I've never seen this behavior before but it makes sense.

OM Gang