Form Fields has On Exit Macro that goes to a Bookmark

D

DeDe

Hi,

I have a form field that has an On Exit maco that changes the status bar
text then goes to a pre-defined bookmark.

The Status Bar part works OK, however, the cursor doesn't move to the
bookmark.

What am I doing wrong?
P.S. I know very little about VBA code.

Thank you in advance.
 
C

Charles Kenyon

Within a protected form you can't move to a bookmark in a protected section
(except a formfield).
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
D

DeDe

Hi Charles,

Thank you for your response.

However, the bookmark is not in a protected section. It is mid-way down an
unprotected section and the cursor lands at the top of the unproteced section
rather than at the bookmark.

Denise
 
G

Greg Maxey

I have a rocket that won't fly to the moon. Why?

Would you be willing to show us your code? ;-)
 
D

DeDe

Hi Greg,

Hope this clarifys it. The code is:

Sub Add4StatusBar()

Application.StatusBar = "Type the letter."

' GoToBookmark named StartLetter

Selection.GoTo What:=wdGoToBookmark, Name:="StartLetter"

End Sub

Thanks in advance
Denise
 
C

Charles Kenyon

I just tried your code in a protected document and it runs fine when run
from the vba editor but when run as an on-exit macro it runs and then the
tab completes and goes to the next formfield. When in the last formfield it
also runs but the tab completes at the beginning of the unprotected section.

You need to either end your unprotected section where you want typing to
begin or put in a wait or timeout into your macro.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
G

Greg Maxey

Dee,

Charles explains what is happening. You can work around it with a
variation of:

Sub Add4StatusBar()
Application.OnTime When:=Now, Name:="ReallyAdd4StatusBar"
End Sub
Sub ReallyAdd4StatusBar()
Application.StatusBar = "Type the letter."
If ActiveDocument.Bookmarks.Exists("StartLetter") Then
ActiveDocument.Bookmarks("StartLetter").Select
End If
End Sub
 
D

DeDe

Hi Greg,

Thank you for your response. I copied your code into the VBA window saved
and re-tested. However, I still had no luck.

Denise
 
G

Greg Maxey

Hmm...it worked for me at work today. The Application.OnTime introduces a
short delay that should get you past the "Tab" effects. Try andding a bit
of delay like this:

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Add4StatusBar()
Application.ScreenUpdating = False
Doze 100
End Sub
Sub Add4StatusBarReally()
If ActiveDocument.Bookmarks.Exists("Details") Then
ActiveDocument.Bookmarks("Details").Select
End If
End Sub
Sub Doze(ByVal lngPeriod As Long)
DoEvents
Sleep lngPeriod
Add4StatusBarReally
End Sub

I didn't test this becasue I didn't take the time to recreate your document.
If it doesn't work I am at a loss.
 
D

DeDe

Hi Greg,
Still no luck - will have to let it go. My thanks to you and Charles for
your attention to this issue.

Kind regards
Denise
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top