Userforms - populating textboxes 
Author Message
 Userforms - populating textboxes

This is the scenario: I have a document with a table. Inside the cells of
the table are about ten bookmarks.

When I launch a userform which has a number of textboxes, I can complete
these boxes and then press OK. This populates the table cells where there
are bookmarks.

That's the easy bit! But now I want to reverse the procedure: After the
table has been populated, I want to open the userform again and each box
should have retrieved the data form the table cells into the appropriate
textbox of the userform. My head is buzzing with arrays, document properties
and so on but I cannot seem to get a handle on this part of the task.

The reason for all this is that I do not want a user to access the table
directly and make changes - they need to do it through the userform.

Can anyone help with this, please?

Regards

Roderick O'Regan



Tue, 16 Nov 2004 06:50:30 GMT  
 Userforms - populating textboxes
Hi, Roderick,

Firstly, when the userform places the text from the textboxes into the table,
you must be sure that the bookmarks remain there and enclose the text -- that
you don't overwrite and destroy the bookmarks, and that you don't place the text
outside the bookmarks. The only sure way to do that is to re-add each bookmark
after you insert the text. This technique is explained at
http://www.mvps.org/word/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

The second part of the puzzle is to put code in the UserForm_Initialize()
procedure of the userform to read the text from the bookmarks into the
textboxes, something like this:

    With ActiveDocument
        Textbox1.Text = .Bookmarks("Text1").Range.Text
        Textbox2.Text = .Bookmarks("Text2").Range.Text
        ' ...
    End With

Because bookmarks are all too easily deleted, this is best preceded by an On
Error Resume Next.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> This is the scenario: I have a document with a table. Inside the cells of
> the table are about ten bookmarks.

> When I launch a userform which has a number of textboxes, I can complete
> these boxes and then press OK. This populates the table cells where there
> are bookmarks.

> That's the easy bit! But now I want to reverse the procedure: After the
> table has been populated, I want to open the userform again and each box
> should have retrieved the data form the table cells into the appropriate
> textbox of the userform. My head is buzzing with arrays, document properties
> and so on but I cannot seem to get a handle on this part of the task.

> The reason for all this is that I do not want a user to access the table
> directly and make changes - they need to do it through the userform.

> Can anyone help with this, please?

> Regards

> Roderick O'Regan



Tue, 16 Nov 2004 08:55:03 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Bookmarks in userforms, how do you populate more then one place

2. Populating combo and listbosex in userforms from access/excel

3. Userform: populate textbox with date from another textbox

4. UserForms, Textboxes & Bookmarks

5. Focus and textboxes on vba userforms

6. Updating textboxes in Word using UserForms fields

7. Userforms - TextBox with spell checking as you type?

8. Populating listboxes and textboxes

9. Populating textboxes from an array

10. populate textbox with contact info

11. How populate field with textbox.text property?

12. querying an access DB to populate a textbox

 

 
Powered by phpBB® Forum Software