Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

set focus requires open VBE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
?rjan Skogl?sa - 08 Nov 2004 12:04 GMT
In a userform I do have the follwing:

If förstaGången Then
 With comboInled
 .SetFocus
 .SelStart = 0
 .SelLength = 100
 End With
Else
 With comboPatNr
 .SetFocus
 .SelStart = 0
 .SelLength = 10
 End With
End If

(comboInled and comboPatnr are dropdowns on the form)

The first time the routines runs, "förstaGången" is True and
"comboInled" is selected. Works perfectly.

From the next time the  routine runs "förstaGången" is False but
"comboPatNr" is not selected no matter how may times the routine runs.

But then I press Alt+F11 and then Alt+F11 again. After that I run once
more without desired result, but from the second run it  works ok.

I do not need to touch anything inside the VBE, it just automatically
shows the userform code and then I toggle back and start the macro.

To be honest I have not really started to search for any error, as it
is not so important, but perhaps someone could suggest something to
look out  for.

TIA
Örjan Skoglösa

PS. I use Word97 on Win2K.
Jonathan West - 08 Nov 2004 15:01 GMT
Hi Örjan

The problem might be that VBA is going too fast for the screen to keep
itself updated. try putting a few DoEvents commands (it often requires more
then one) into the routine immediately after the second End With statement.
DoEvents tells Windows to stop running the macro briefly and go and check
the Windows message queue (mostly for commands to update the ecreen)

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

> In a userform I do have the follwing:
>
[quoted text clipped - 34 lines]
>
> PS. I use Word97 on Win2K.
?rjan Skogl?sa - 13 Nov 2004 10:16 GMT
Hi Jonathan,

(Sorry for the delayed reply, but I have been "offline" for some
days.)

I guess this is a stupid question, but what kind of event should I
use?

If have tried to insert empty "Do -> Loop" statements, but that does
not show any effect.

TIA
Örjan

>Hi Örjan
>
[quoted text clipped - 3 lines]
>DoEvents tells Windows to stop running the macro briefly and go and check
>the Windows message queue (mostly for commands to update the ecreen)
Helmut Weber - 13 Nov 2004 12:36 GMT
Hi Örjan,
doevents is nothing specific, just see help for "doevents".
I guess, Jonathan means something like:
for i = 1 to x
  doevents
next
You may also try to combine "doevents" with "sleep".
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds
As Long).
Beware of possible linebreaks.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
?rjan Skogl?sa - 14 Nov 2004 11:10 GMT
Hi Helmut,

Thanks for your explanation. I thought the command was "DoEvent" and
tried to find that. Now I get it.

Sadly, it does not help. Nor does your complementary advice, at least
if I got it right (see below*).

Perhaps I did not explain correctly.

If I start Word, open a new document on the template with the macro
and then run the macro, the selection in the else clause will never be
executed.

If I start Word, open a new document on the template with the macro
but then (just) open the macro editor before I run the macro,  the
selection in the else clause will not be executed the first time it
should, but after that  as it is intended.

If I then close the editor again, the selection will be executed as it
should one more time, but after that not any more.

==============

I think I will let this case rest for now and perhaps next weekend try
to more systematically trace the flow in the macro and hopefully come
back then.

TIA

Örjan

*
If förstaGången Then
 With comboInled
 .SetFocus
 .SelStart = 0
 .SelLength = 100
 End With
Else
 With comboPatNr
 .SetFocus
 .SelStart = 0
 .SelLength = 10
 End With
Dim x
x = 1000
For i = 1 To x
  DoEvents
 Sleep 1000
Next

Btw, does the macro execution wait for the "sleep" to be finished? I
have the feeling it does not.

>Hi Örjan,
>doevents is nothing specific, just see help for "doevents".
[quoted text clipped - 12 lines]
>Word XP, Win 98
>http://word.mvps.org/
Helmut Weber - 14 Nov 2004 12:39 GMT
Hi Örjan,
to let a problem rest for a while, is a good idea.
Helped me a lot.
Besides of some lines, which I don't understand:
>x = 1000
>For i = 1 To x
>   DoEvents
>  Sleep 1000
>Next
would cause a timeout of 1000 seconds!
x = 1000, sleep 1000 (= 1000 milliseconds = 1 second)
= 1000 seconds
---
BTW, where are you from?
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
?rjan Skogl?sa - 14 Nov 2004 16:25 GMT
Oops, I did not calculate, I just started with a number that surely
would be enough and then added "the sleep" in the same way.  

But it also is interesting to find out that it did not cause any real
timeout. The only effect I realized was slowness.

Until then.

BR,
Örjan

PS. I´m swedish and live in the south of Sweden but was raised in
Hamburg.

>Hi Örjan,
>to let a problem rest for a while, is a good idea.
[quoted text clipped - 15 lines]
>Word XP, Win 98
>http://word.mvps.org/
Helmut Weber - 14 Nov 2004 20:02 GMT
Hi Örjan,
it seems, "timeout" wasn't clear enough,
or just the wrong word.
What I meant was "pause".
Bye.
---
Helmut Weber
?rjan Skogl?sa - 21 Nov 2004 12:02 GMT
Just FYI

I discovered that I hid the userform between runs.

Thus the routine "activate" was not executed. Or to be more precise,
it was not executed when the VBE was closed. Now I use unload instead
of hide and the problem has disappeared.

Just out of curiosity I made a little test and could confirm that with
my constellation (Word97 on Win2K) the built-in routine
UserForm_Activate only is run (after the userform has been hidden) if
the editor is open.

Best regards,
Örjan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.