Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-02-20
9
Medium Priority
?
289 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:cazink
  • 3
  • 3
  • 3
9 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 23697105
Can you post a screen shot of the VBE with the red text please?

OM Gang
0
 

Author Comment

by:cazink
ID: 23697285
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.  
0
 
LVL 28

Expert Comment

by:omgang
ID: 23697314
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58

Expert Comment

by:harfang
ID: 23697769
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°)
0
 

Author Comment

by:cazink
ID: 23698395
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?
0
 
LVL 58

Accepted Solution

by:
harfang earned 375 total points
ID: 23701343
Well, that is the solution, I believe.

If any VB code is running while you try to edit a module, you will experience what you saw (immediate syntax correction while you type, which makes it nearly impossible to edit any code at all). An open form with a timer event is one way to have VB code execute repeatedly, but there are a few others. If you don't want this behaviour (and who would?), make sure no part of your project is running.

Normally, you can indeed edit the code behind a form while it's open (and it's a useful debugging tool as well), except if you have an active timer event, in the same form or in another. The risk of corruption is higher when you have several instances of the same class module, but that is a rare technique for forms. What I'm saying is that most developers do debug live forms all the time, although this can cause problems in some special cases, among which the one you describe.

Does that answer your question better?
(°v°)
0
 

Author Comment

by:cazink
ID: 23701931
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
0
 
LVL 58

Expert Comment

by:harfang
ID: 23702110
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°)
0
 
LVL 28

Expert Comment

by:omgang
ID: 23712370
harfang, thanks for the detailed information.  As I mentioned, I've never seen this behavior before but it makes sense.

OM Gang
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question