Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2015, 04:20 AM
PeterPlys PeterPlys is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 8 Form updating Bookmarks - writes to the bookmarks multiple times Office 2013
Novice
Form updating Bookmarks - writes to the bookmarks multiple times
 
Join Date: Jan 2015
Location: Denmark
Posts: 7
PeterPlys is on a distinguished road
Default Form updating Bookmarks - writes to the bookmarks multiple times

I have a template with one form having 3 fields that runs 1 time when a new doc is created.
I assign the input to 3 variables and
assign the variables to bookmarks in the footer of the document.



That works fine.

Then I start to write the text in the document and sometimes the input stops to appear on the screen and the bookmarks in the footer have their content added one time every time I press enter. I have this on several PCs now.

My code for the form is:

Code:
Private Sub CommandButton1_Click()
Set Snr = ActiveDocument.Bookmarks("Snr").Range
Snr.Text = Me.TextBox1.Value
Dim Bes As Range
Set Bes = ActiveDocument.Bookmarks("Bes").Range
Bes.Text = Me.TextBox2.Value
Dim Ini As Range
Set Ini = ActiveDocument.Bookmarks("Ini").Range
Ini.Text = Me.TextBox3.Value
UserForm1.Hide
End Sub
My 3 bookmarks are named: Snr, Bes and Ini


Any ideas?
Reply With Quote
  #2  
Old 01-13-2015, 09:20 PM
macropod's Avatar
macropod macropod is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 7 64bit Form updating Bookmarks - writes to the bookmarks multiple times Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Ideally, you'd only press Enter once. However, the basic problem is that you're not updating the bookmarks - you're simply using them as placeholders to insert the text. To update the bookmarks, you should be using code like:
Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Call UpdateBookmark("Snr", Me.TextBox1.Value)
Call UpdateBookmark("Bes", Me.TextBox2.Value)
Call UpdateBookmark("Ini", Me.TextBox3.Value)
Application.ScreenUpdating = True
UserForm1.Hide
End Sub
 
Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
  End If
End With
Set BkMkRng = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-13-2015, 11:36 PM
PeterPlys PeterPlys is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 8 Form updating Bookmarks - writes to the bookmarks multiple times Office 2013
Novice
Form updating Bookmarks - writes to the bookmarks multiple times
 
Join Date: Jan 2015
Location: Denmark
Posts: 7
PeterPlys is on a distinguished road
Default

Thanks.

The first part of your code is in place.
I do not know where to put the second part of your code and when to run it.

Could you clarify that for me?
Reply With Quote
  #4  
Old 01-13-2015, 11:47 PM
macropod's Avatar
macropod macropod is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 7 64bit Form updating Bookmarks - writes to the bookmarks multiple times Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You use the lot exactly as I posted it. Even so, the order in which you insert the subs doesn't matter.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 01-14-2015, 12:56 AM
PeterPlys PeterPlys is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 8 Form updating Bookmarks - writes to the bookmarks multiple times Office 2013
Novice
Form updating Bookmarks - writes to the bookmarks multiple times
 
Join Date: Jan 2015
Location: Denmark
Posts: 7
PeterPlys is on a distinguished road
Default

Sorry I was too quick on the keyboard ... I should have read the code one more time before posting - sorry about that.

Your suggestion is doing this:

As before the bookmarks are being filled out ...

But when I start to type rest of the text in the document and a couple of lines down hit enter to start a new line and then hit enter again to have a blank line nothing happens .

If I type a space or a character, I can type on.

Your code has stopped the bookmarks to have their content added every time I press enter when the input stops to appear on screen.
Reply With Quote
  #6  
Old 01-14-2015, 01:15 AM
macropod's Avatar
macropod macropod is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 7 64bit Form updating Bookmarks - writes to the bookmarks multiple times Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I think you need to explain more clearly what you're doing with the document. The code I posted has no effect whatsoever on anything you type into the document or your userform - all it does is to ensure that clicking on CommandButton1 doesn't keep adding new content.

If your document is misbehaving, I can't really comment on that without seeing it. Can you attach a document to a post with some representative data, including your userform (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 01-14-2015, 01:54 AM
PeterPlys PeterPlys is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 8 Form updating Bookmarks - writes to the bookmarks multiple times Office 2013
Novice
Form updating Bookmarks - writes to the bookmarks multiple times
 
Join Date: Jan 2015
Location: Denmark
Posts: 7
PeterPlys is on a distinguished road
Default

Here is my setup

brev.dotm is the template I use to open a new letter
placed in workgroup templates.

mp2015.docm
is placed in startup

Blank/new Normal.dotm
is in user templates

enclosed 3 files
Attached Files
File Type: dotm MP2015.dotm (17.6 KB, 11 views)
File Type: docm Brev.docm (27.2 KB, 12 views)
File Type: dotm Normal.dotm (18.3 KB, 11 views)
Reply With Quote
  #8  
Old 01-14-2015, 02:18 AM
macropod's Avatar
macropod macropod is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 7 64bit Form updating Bookmarks - writes to the bookmarks multiple times Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

So which file are you having trouble with? I opened your MP2015.dotm & Normal.dotm files and can see nothing special about them - your Normal.dotm doesn't even contain any code. Indeed I can't even see how those files might be related to what's in this thread. I also opened your Brev.docm file and can see that, apart from your Document_New macro needing the same kind of changes made for the userform, it seems to work OK. Presumably, it too should be saved as a template; otherwise your Document_New macro will never run.
Code:
Private Sub Document_New()
    Call UpdateBookmark("DagsDato", Format(Date, " dd. mmmm yyyy"))
    UserForm1.Show
End Sub
 
Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
  End If
End With
Set BkMkRng = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 01-14-2015, 02:52 AM
PeterPlys PeterPlys is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 8 Form updating Bookmarks - writes to the bookmarks multiple times Office 2013
Novice
Form updating Bookmarks - writes to the bookmarks multiple times
 
Join Date: Jan 2015
Location: Denmark
Posts: 7
PeterPlys is on a distinguished road
Default

sorry wrong file uploaded .....

here is the correct Brev.dotm
Attached Files
File Type: dotm Brev.dotm (27.4 KB, 14 views)
Reply With Quote
  #10  
Old 01-14-2015, 05:28 AM
macropod's Avatar
macropod macropod is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 7 64bit Form updating Bookmarks - writes to the bookmarks multiple times Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your template would work better if you had either the AutoNew macro or the Document_New macro. Presently, both load the userform, requiring everything to be input twice. Personally, I'd be inclined to use just the Document_New macro (it doesn't try to update the bookmark) and, instead of using code to insert the date, just use a CREATEDATE field in the header. Aside from that, I have no problems updating the document once the userform has closed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 01-14-2015, 06:14 AM
PeterPlys PeterPlys is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 8 Form updating Bookmarks - writes to the bookmarks multiple times Office 2013
Novice
Form updating Bookmarks - writes to the bookmarks multiple times
 
Join Date: Jan 2015
Location: Denmark
Posts: 7
PeterPlys is on a distinguished road
Default

The problem does not occur in all new documents based on the brev.dotm template.
And sometimes it occurs more than one time in the same document.

I can type in the adressee and the Re: line and maybe 2-3 paragraphs before it happens.
Reply With Quote
  #12  
Old 01-14-2015, 06:23 AM
macropod's Avatar
macropod macropod is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 7 64bit Form updating Bookmarks - writes to the bookmarks multiple times Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As I have already said, you template has both an AutoNew macro and a Document_New macro. Those macro both load your userform, requiring the data to be input twice. That's why you'll see it flicker and clear after the first time you input the data then close the form. If you check both the NewMacros module and the ThisDocument module in the template, you'll see what I am talking about.

As for what happens once the userform has closed, that has nothing to do with any code related to the userform. It is likely to be due to other things going on in your system - the problem does not occur on my system.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 01-14-2015, 06:36 AM
PeterPlys PeterPlys is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 8 Form updating Bookmarks - writes to the bookmarks multiple times Office 2013
Novice
Form updating Bookmarks - writes to the bookmarks multiple times
 
Join Date: Jan 2015
Location: Denmark
Posts: 7
PeterPlys is on a distinguished road
Default

Sorry for not being clear .

I have corrected the Document_New and the AutoNew - only one is in use now.

It has just been tested on 2 PCs in another organisation ...
same problem.

If i remove all code from the template - no problem.
Reply With Quote
  #14  
Old 01-14-2015, 06:41 AM
macropod's Avatar
macropod macropod is offline Form updating Bookmarks - writes to the bookmarks multiple times Windows 7 64bit Form updating Bookmarks - writes to the bookmarks multiple times Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

On my system there is 0 delay between typing and the appearance of the content on screen. Since the code in the template isn't running when I'm typing (or when you are typing), that is not the cause. I suggest you look at what else is running on your system, including any 3rd-party Word Addins that might be compromising things.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
bookmark, form, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't See Bookmarks bobmayo Word 21 06-04-2013 07:37 AM
make a form that can be used multiple times at once Dsp581 Excel 19 04-05-2013 07:25 AM
Form updating Bookmarks - writes to the bookmarks multiple times Word only writes top half of input in form Chippychap Word 8 07-20-2012 12:49 AM
Form updating Bookmarks - writes to the bookmarks multiple times VBA code to extract specific bookmarks from multiple word files Rattykins Word VBA 4 06-27-2012 10:02 PM
Bookmarks for a PDF? Ownaholic Word 0 10-30-2010 12:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft