retrieve data back to userform

A

Associates

Hi,

I have a problem with bookmarks. I have a userform called "New application
form" made up for a template .dot. In the word, i have insert bookmarks that
correspond to the text fields in the userform. So, when user finishes filling
out the fields and hit "OK" button, all the data are put into bookmarks.

However, what i'm trying to do now is to be able to retrieve all those data
back from bookmarks to the form. I know the code to retrieve values from
bookmarks to textfields in the userform. The reason for this is to allow user
to edit some of the data through the form. (don't know if by doing this, i
have made my life more difficult). Anyway, i created another userform called
"Editing application form" and a Edit button (use macro). So when user clicks
on this button, it brings up the "Editing application form" with all the data
in their appropriate text fields.

The problem here is When user hits "Edit now" button, i got error message
saying
"The requested member of the collection doesn't exist". When i checked the
bookmarks, those bookmarks are not there. I believe this is because they are
not entered in the first place during the creation of the new application
form. (something new i learn again today)

so is there any other ways that i could use apart from bookmarks and still
helps resolve my issue?

Thank you in advance
 
D

Doug Robbins - Word MVP

Instead of bookmarks, use { DOCVARIABLE varname } fields and then you set
and get the data by using the .Value attribute of the variables.

With ActiveDocument
.Variables("varname").Value = txtvarname.Text
etc
End With

and to retrieve the information, reverse the bits either side of the = sign.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Associates

Thank you Doug for your reply.

This is what i'm after. However, because this is a new thing to me, I got
troubled implementing it. I have googled it and found the steps as below

1. On the Insert menu, click Field.
2. In the Categories box, select Document Automation.
3. In the Field names list, select DocVariable.
4. In the New Name box, under Field properties, type the name of the
document variable.
5. Click OK

I put the cursor in the area where i want this {DOCVARIABLE "test"} to be
and followed the steps above. After clicking "OK" button, nothing happens. I
don't see {DOCVARIABLE "test"} any where in the document. I wonder what else
are missing here. I tried it a different way but to no avail :(

I really appreciate your patience.

Thank you in advance
 
D

Doug Robbins - Word MVP

With the cursor at the location in the document where you want the data to
appear, Press Ctrl+F9 to insert a pair of field delimiters { } and inside
them type DOCVARIABLE test

{ DOCVARIABLE test }

You must use Ctrl + F9 to insert the { }

Actually however if you toggle the display of the fields using Alt+F9 in the
document that you already have, you will probably see the field that you
inserted via the menu system

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Associates

Hi Doug,

Sorry, i'm still struggling to get it to work. What you have said and shown
are very clear to me but i don't understand why the { DOCVARIABLE test } did
not get replaced with the value of the Textvarname.

In the template .dot, i did ctrl + F9 and {} came out ready for me to enter
something inside it. So i typed in (in capital) { DOCVARIABLE test }. It was
highlighted when i clicked on it.

Anyway, in the userform, i have a textbox called txtvarname and a button
called "OK".

In the "OK" button, i have the codes you gave (a very simple test)
With ActiveDocument
MsgBox txtvarname.Text
.Variables("test").Value = me.txtvarname.Text
End With

me.hide ' hide the form

After i clicked "OK", that { DOCVARIABLE test } was still there. it didn't
change or get replaced. Then, i thought that this might be to do with the
template. Maybe it didn't work well with Template. I tested it with a normal
document and the result was still the same.

Sorry, i'm sure this should be a trivial case but don't understand why it
didn't work for me :(

I use office 03 by the way.

Thank you once again in advance
 
A

Associates

Hi Doug,

I have just found out the reason why { DOCVARIABLE test } did not get
replaced by the value of txtvarname in the document. Actually, it did get
replaced but i needed to do "Update field" first (right click on it while
it's being highlighted) and then toggle it . Then, the value will show up
when doing print preview. Is this the way it works?

How do i update the field in VBA codes? because we don't want user to right
click on it to update the field everytime they use the template.

Thank you in advance
 
D

Doug Robbins - Word MVP

You need to include some code the update the fields in the document. The
quick and easy way to do it is to use

With ActiveDocument
.PrintPreview
.ClosePrintPreview
End With

which will work as long as the Update fields on Print box is checked in the
Print Options dialog.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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