Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 07-15-2015, 04:27 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

If I run the macro in the doc you sent me, it works fine. If I change the "BkMk" to anything else if gives me the "Bookmark:XXX not found", and does not insert a form field. What am I missing here? Thanks-
Reply With Quote
  #17  
Old 07-15-2015, 04:32 AM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements 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

Quote:
Originally Posted by brent chadwick View Post
If I run the macro in the doc you sent me, it works fine. If I change the "BkMk" to anything else if gives me the "Bookmark:XXX not found", and does not insert a form field. What am I missing here?
Please have another read of what I said:
Quote:
Originally Posted by macropod View Post
You can use another name, of course, but you need to use the same name in both the document and the macro.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 07-15-2015, 04:58 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

If I use it in the doc I'm working, and give it the bookmark of the drop-down menu, it erases the drop-down menu. If I give it the bookmark of any other form field in the doc, it erases and replaces that form field. So it is not giving an additional (new) form field. Thanks-
Reply With Quote
  #19  
Old 07-15-2015, 05:33 AM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements 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

Quote:
Originally Posted by brent chadwick View Post
If I use it in the doc I'm working, and give it the bookmark of the drop-down menu, it erases the drop-down menu.
I wouldn't expect anything else! The dropdown's bookmark should most certainly be referenced in the code.
Quote:
If I give it the bookmark of any other form field in the doc, it erases and replaces that form field. So it is not giving an additional (new) form field.
Again, that's exactly what one should expect. As I said in a previous post:
Quote:
The bookmark named 'BkMk' is one you create in the document, via Insert|Bookmark
Obviously, if you're chnaging the macro to use a bookmark already assigned to another formfield, you're not using one you've created via this process.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #20  
Old 07-15-2015, 06:35 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

So, I'm really confused. When the drop-down menu is XX, I want the exit macro to create a new additional form field. Am I explaining correctly or not?
Reply With Quote
  #21  
Old 07-15-2015, 06:46 AM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements 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

Quote:
Originally Posted by brent chadwick View Post
So, I'm really confused. When the drop-down menu is XX, I want the exit macro to create a new additional form field.
Well, except for the 'XX', which you originally said was '1000', if you have a look at the document I provided, you'll see it does exactly that.

To determine where the dependent text formfield should go, a bookmark is needed. To that end, the document I provided has a bookmark named 'BkMk' at the destination. The macro likewise refers to that bookmark - not the dropdown's bookmark or any other formfield's bookmark. So, if you want to use the macro, you need to do likewise. Your bookmark name doesn't have to be 'BkMk' but, if you decide to use any other name, you must create the bookmark via Insert|Bookmark and edit the macro to refer to that name.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #22  
Old 07-15-2015, 10:06 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

OK, I finally got it. In the macro that inserts all of this stuff I have to create a bookmark for the new form field to go to. One more question and I'll stop bugging you-I would like to add default text to the new form field. How do I do that? You have been a great help, I have learned much. Too much to learn and so little time-Thanks
Reply With Quote
  #23  
Old 07-15-2015, 05:18 PM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements 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

Quote:
Originally Posted by brent chadwick View Post
I would like to add default text to the new form field. How do I do that?
You can do that by inserting after:
.FormFields.Add BmkRng, wdFieldFormTextInput
the line:
BmkRng.FormFields(1).TextInput.EditType wdRegularText, "My default text"
where "My default text" is whatever you want for the default.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #24  
Old 07-17-2015, 04:51 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

The code works great. With this drop-down though I have three additional form fields that are conditional. I have tried working with the code you wrote and I get several error codes. Suggestions?

Do you have a book/books that I can read on the VBA subject? I have Mastering VBA and on other on and both of them do not define terms etc. that I can understand. Suggestions? Thanks-
Reply With Quote
  #25  
Old 07-17-2015, 05:44 AM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements 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

Without seeing your code, plus the document you're trying to populate, you can't really expect anyone to give specific advice on what's wrong...

As for VBA programming books, I can't give specific recommendations - all my VBA skills are self-taught (mostly through helping people in forums such as this).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #26  
Old 07-17-2015, 05:51 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

I can send you whatever you like.
Reply With Quote
  #27  
Old 07-17-2015, 03:06 PM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements 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 could attach a document to a post, just as I did earlier in this thread, with some representative data (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
  #28  
Old 07-18-2015, 04:37 AM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

Here's the doc that has all of the text that the macro needs to produce. The years (1790-1940) are in a drop-down menu. The regular non-conditional form fields are the grey highlighted ones. There are 6 conditional form fields depending on the chosen year highlighted in yellow. There is one conditional drop-down menu (AorB).
What is done-
The year drop-down. All of the text and conditional text. All of the bookmarks for the conditional form fields.
What I need help on-
The conditional form fields and the one conditional drop-down menu.

Here is the drop-down exit macro which I am assuming where the additional code needs to go. I have tried to write it and failed miserably.

Code:
Sub LockDD1()
'
' Exit macro
'
'

Dim Prot As Variant, BmkRng As Range
Const BmkNm As String = "Column" ' The bookmark name
With ActiveDocument
  Prot = .ProtectionType
  If .ProtectionType <> wdNoProtection Then
    Prot = .ProtectionType
    .Unprotect Password:=Pwd
  End If
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    If .FormFields("DD1").Result = "1790" Then
      .FormFields.Add BmkRng, wdFieldFormTextInput
      BmkRng.FormFields(1).TextInput.EditType wdRegularText, "X,"
      Else
      BmkRng.Delete
End If
    .Bookmarks.Add BmkNm, BmkRng
  Else
    MsgBox "Bookmark: " & BmkNm & " not found."
  End If
  .Protect Type:=Prot, NoReset:=True
End With
Set BmkRng = Nothing

     Application.ScreenUpdating = False
    If ActiveWindow.View.Type = wdPageView Then
        ActiveWindow.ActivePane.View.Type = wdNormalView
    Else
        ActiveWindow.View.Type = wdPageView
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Then
        ActiveWindow.ActivePane.View.Type = wdPageView
    Else
        ActiveWindow.ActivePane.View.Type = wdNormalView
    End If
    End Sub
BTW kudos to you and being self taught-I too am self taught but at least a couple of light-years behind-Thanks
Attached Files
File Type: docx Latest EE Updates for U.S. Census.docx (125.8 KB, 12 views)
Reply With Quote
  #29  
Old 07-18-2015, 06:15 PM
macropod's Avatar
macropod macropod is offline Help with if then statements Windows 7 64bit Help with if then statements 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

There's no fields of any kind in your document, so it's far from apparent what you're expecting. All I can see is plain text, some of which has grey highlighting and some of which has yellow highlighting.

Does you real document have all these paragraphs, or are the ones in your attachment simply the conditional variations on a single paragraph?

You say you've done "The year drop-down. All of the text and conditional text. All of the bookmarks for the conditional form fields.", but none of these is present in your document. Nor is the code you're using to drive the process - the macro you posted certainly couldn't do any more than conditionally add a single formfield; it can't even do conditional text. As some of your paragraphs have additional strings, such as 'population schedule,' 'col.', 'line' 'dwelling' and 'family', I'm guessing they're your conditional text, but there's no indication of whether that's so.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #30  
Old 07-19-2015, 01:20 PM
brent chadwick brent chadwick is offline Help with if then statements Windows 8 Help with if then statements Office 2013
Advanced Beginner
Help with if then statements
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

Here's the doc that the macros are in, there is no text in it because the macro creates all of the text that the other doc has-
Attached Files
File Type: dotm Forum test code.dotm (116.9 KB, 13 views)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with if then statements Multiple If statements, Jamal NUMAN Excel 16 11-15-2022 11:59 PM
Countif statements Alaska1 Excel 5 02-05-2015 07:55 PM
Help with if then statements Using IF statements stuwoolf Excel 2 01-10-2015 01:58 PM
Help with if then statements count if statements Alaska1 Excel 1 05-14-2014 08:21 AM
IF statements that shifts to right. kent Excel 0 01-19-2006 02:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:14 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