Userform and routine questions

J

Jason Logue

Okay, I have posted similar queries on this same topic before, but I
don't think any of my previous posts really clarified my quandry.
Here is the main problem:

1) I have four main userform windows that users enter info into and
this info is inserted in bookmarked text within a template.

2) The user will need to access particular sub-divided sections in a
large manual at certain points during the userform entry process. I
placed a button that allows access to a first window with a listing of
all chapters in the manual. When they click on a chapter, they can
then click on a section number button (e.g. 1.1 is Chapter 1.1) and
that retrieves bookmarked sections (the 1.1. button retrieves the
bookmark Chapter1_1).

3) When the user clicks on the final section number button, the
bookmarked text is placed in the original main userform and in a
certain textbox next to the button they clicked on. So if they need
to insert text from the manual in a certain area, they will click on
the button next to the textbox.

4) Up until the final section number button, the code is simply a
series of Userformname.Show and PreviousUserform.Hide. Quite simple.
On the final button, though, the code is summed up in one line:

NameofUserform.Nameoftextboxtextisinsertedinto.Text =
Source.Bookmarks(nameofbookmarkedtext).Range

This is telling the button to retrieve the bookmarked text and insert
it in the named textbox in the named userform.

My main problem is that the userform and textbox must be variables,
else I have to repeat all the code over and over again for each
different textbox. There are only four userforms and there will
probably be around ten textboxes, but the bookmarks number above 100.

I apologize for essentially posting the same question three times, but
I felt like I never really made myself clear. I hope this helps.

TIA,
Jason
 
W

Word Heretic

G'day (e-mail address removed) (Jason Logue),

a) what is going wrong?

b) are you showing the form after setting the text of the button?


(e-mail address removed) (Jason Logue) was spinning this yarn:
Okay, I have posted similar queries on this same topic before, but I
don't think any of my previous posts really clarified my quandry.
Here is the main problem:

1) I have four main userform windows that users enter info into and
this info is inserted in bookmarked text within a template.

2) The user will need to access particular sub-divided sections in a
large manual at certain points during the userform entry process. I
placed a button that allows access to a first window with a listing of
all chapters in the manual. When they click on a chapter, they can
then click on a section number button (e.g. 1.1 is Chapter 1.1) and
that retrieves bookmarked sections (the 1.1. button retrieves the
bookmark Chapter1_1).

3) When the user clicks on the final section number button, the
bookmarked text is placed in the original main userform and in a
certain textbox next to the button they clicked on. So if they need
to insert text from the manual in a certain area, they will click on
the button next to the textbox.

4) Up until the final section number button, the code is simply a
series of Userformname.Show and PreviousUserform.Hide. Quite simple.
On the final button, though, the code is summed up in one line:

NameofUserform.Nameoftextboxtextisinsertedinto.Text =
Source.Bookmarks(nameofbookmarkedtext).Range

This is telling the button to retrieve the bookmarked text and insert
it in the named textbox in the named userform.

My main problem is that the userform and textbox must be variables,
else I have to repeat all the code over and over again for each
different textbox. There are only four userforms and there will
probably be around ten textboxes, but the bookmarks number above 100.

I apologize for essentially posting the same question three times, but
I felt like I never really made myself clear. I hope this helps.

TIA,
Jason

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 
J

Jason Logue

Steve, et al,

Here is some of the code. I have put the code under modules, and put
a line in the userforms to call this code, but it's just not working.
I need this code to be generic enough, so that if they click on a
Button_4 in Userform3, any text they grab will populate the textbox
adjacent to Button_4 on the Userform. Here is a sampling of the code.
I know this is probably not right, but like I've said before, I'm
still a newbie:

Public Sub ButtonClick()


Dim i As Integer, source As Document, target As Textbox 'The idea here
is to dim the source document called (which is below), and dim any
textbox adjacent to a certain button on the userform'

Set source = Documents.Open("C:\Documents and Settings\Logue\My
Documents\Allied Title\exceptions\exceptions.doc") ' This where all
the bookmarked text is pulled from


Chapters1a.Show ' After they click the first button on the main
userform, a list of all the chapters within the Exceptions.doc
appears, or at least is supposed to. Right now this seems to be
working.'


'In the following code, I wanted it to work so that if they click
CommandButton1 (representing chapter 1), then that would open up
another window (Chapter1a.Show) and close the previous window.

If CommandButton1_Click Then


Chapters1a.Hide

Chapter1a.Show

End If
If CommandButton2_Click Then

Chapter2a.Show

Chapters1a.Hide

End If

'The above code is repeated 27 times for the 27 chapters in the source
document.

'Now, this is where things really didn't work. If the user clicked
Chapter 1 button, then all the sections in that chapter appeared on
another userform, and this was Chapter1a. So then if they
Commandbutton1 (representing bookmarked text Chapter1_1, as seen
below), this would grab that text and insert it in the appropriate
textbox. This appropriate textbox depends all upon the adjacent
Commandbutton (ExceptionsBUtton1_Click) clicked on the original
userform discussed much earlier in this message. Otherwise,
bookmarked text could be deposited in the entirely wrong textbox and
that would be no good. As you can see below, my goal is to make
userform and textbox values for the location of the
exceptionsbutton_click they choose. And this is the main problem, how
do I have the code determine that?


If CommandButton1_Click = True Then

Chapter1a.Hide

If ExceptionsButton1_Click = True Then

UserForm.Textbox.Text =
source.Bookmarks("Chapter1_1").Range

End If


End If

FWIW, I had a lot of this worked out, but it involved quite a bit of
duplication and increased the size of the template a bit too much for
my tastes.

Any help is appreciated.

TIA,
Jason
 
W

Word Heretic

G'day (e-mail address removed) (Jason Logue),

Hmmm. I think you've ballsed up the method. FWIW, I sell a mate's
stand-alone product that builds docs through multiple choice
selections that would be easier to use than writing this macro. Email
me offlist if you are interested. About 100 bux.

Anyway, what you should be doing is this.

One main routine builds userforms from the data as required. I think
you can use the me.name of a button click to gen the button name as a
parm to your general routine. I'd probably be going for list boxes
myself, and double-clicking an entry to insert it. The the listindex
gives us a nice usable offset.

The form should be dumb, with the logic in the calling routine(s). Use
properties of the form, eg Property_Get etc., to pass the selected
values back to the host program. You can also just query the form's
controls directly. The host then repops the listbox with whatever new
data is required and shows it again. One userform, constantly changing
data represented in it.


(e-mail address removed) (Jason Logue) was spinning this yarn:
Public Sub ButtonClick()


Dim i As Integer, source As Document, target As Textbox 'The idea here
is to dim the source document called (which is below), and dim any
textbox adjacent to a certain button on the userform'

Set source = Documents.Open("C:\Documents and Settings\Logue\My
Documents\Allied Title\exceptions\exceptions.doc") ' This where all
the bookmarked text is pulled from


Chapters1a.Show ' After they click the first button on the main
userform, a list of all the chapters within the Exceptions.doc
appears, or at least is supposed to. Right now this seems to be
working.'


'In the following code, I wanted it to work so that if they click
CommandButton1 (representing chapter 1), then that would open up
another window (Chapter1a.Show) and close the previous window.

If CommandButton1_Click Then


Chapters1a.Hide

Chapter1a.Show

End If
If CommandButton2_Click Then

Chapter2a.Show

Chapters1a.Hide

End If

'The above code is repeated 27 times for the 27 chapters in the source
document.

'Now, this is where things really didn't work. If the user clicked
Chapter 1 button, then all the sections in that chapter appeared on
another userform, and this was Chapter1a. So then if they
Commandbutton1 (representing bookmarked text Chapter1_1, as seen
below), this would grab that text and insert it in the appropriate
textbox. This appropriate textbox depends all upon the adjacent
Commandbutton (ExceptionsBUtton1_Click) clicked on the original
userform discussed much earlier in this message. Otherwise,
bookmarked text could be deposited in the entirely wrong textbox and
that would be no good. As you can see below, my goal is to make
userform and textbox values for the location of the
exceptionsbutton_click they choose. And this is the main problem, how
do I have the code determine that?


If CommandButton1_Click = True Then

Chapter1a.Hide

If ExceptionsButton1_Click = True Then

UserForm.Textbox.Text =
source.Bookmarks("Chapter1_1").Range

End If


End If

FWIW, I had a lot of this worked out, but it involved quite a bit of
duplication and increased the size of the template a bit too much for
my tastes.

Any help is appreciated.

TIA,
Jason

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 

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