Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-populating fields from form input...

Status
Not open for further replies.

Maven4Champ

Technical User
Jun 16, 2004
154
This may or may not be possible. I have a form that a co-work and I
have been working on that is used to populate alot of information. The
problem is, some of the users of the form don't always have "all"
their information the first time they go to start filling information
in.

WIth that said, I need code or instructions on how we can change the
form so that when the user submits partial information - that info is
parsed to the document BUT if they save it and close and go back in,
when the form auto-opens, their partial information is still populated
in the form.


This way, the user doesn't lose their information upon re-submitting
the form with more complete information. Is this possible to store or
cache the information in the form itself?


Thanks!
 
1. We need to know what application you are talking about. It look like it is for Word...but....

2. We need to know how you are putting the info in. Bookmarks? Formfields (if it is Word)?

3. Is not putting that info into the document a form of storing? You state
that info is
parsed to the document BUT if they save it and close and go back in,
when the form auto-opens,
That sure sounds like the info is put into the document. If so, then...there it is.

4. WHY are you doing this after the fact? Why do you not do this validation before form closes?

5. The userform takes into and puts in the document, so it can just as easily take information from the document and put it in the userform.

Basically, the issue is one of logic. if you have validation routines, you need to (or seem to want to) apply that logic at some point.

Do you have that logic worked out? That is, do you know precisely how you are determining what is partial, and what is not?

Gerry
My paintings and sculpture
 
I am using Microsoft Word 2000 and VB Editor and UserForms.

I am using bookmarks in my word document, populated from the input fields on the UserForm.

The data does populate into the word document.

My problem is this.

As an example, create a form with 3 form fields and a word document with 3 bookmarks tied back to those 3 fields.

Then launch the form and fill in 2 of the three forms and hit SUBMIT.

Save the form and close out.

Open the form and launch the form again and fill out any of the three fields. You will notice the other two fields you typed data in previously are wiped out.

Since our users are form-dependent, we can't ask them to go in an cancel the form and manually type in data, especially because it is locked.

With that said, I need to pass data in the document back to the form so it's editable and doesn't get lost upon a new submission.
 
Hi Maven4Champ,

You can deal with this by reading the bookmarks. If they're empty, initialise the userform with your default text; otherwise, initialise with the bookmark contents.

Cheers

[MS MVP - Word]
 
I presume you mean a userform with three textboxes.

Now, in the document are they BOOKMARKS getting filled in, or FORMFIELDS getting filled in?

In any case, it does not really matter. macropod is correct. Use the Initialize event of the form to fill in the userform textboxes.

Let's say you have three formfields in the document (note: formfields...not bookmarks, but you could use bookmarks). And you have three textboxes on the userform. I am using the default names. Hopefully you are not.
Code:
Sub UserForm1_Initialize()
If ActiveDocument.Formfields("Text1").Result <> "" Then
   Textbox1.Text = ActiveDocument.Formfields("Text1").Result
End If
If ActiveDocument.Formfields("Text2").Result <> "" Then
   Textbox1.Text = ActiveDocument.Formfields("Text2").Result
End If
If ActiveDocument.Formfields("Text3").Result <> "" Then
   Textbox1.Text = ActiveDocument.Formfields("Text3").Result
End If
End Sub
The userform will pick up the existing text (if any) from the formfields in the document, when it opens.

The current text of the textboxes, of course, goes the other way. I assume there is a CommandButton to do this.
Code:
Sub CommandButton1_Click()
With ActiveDocument
  .Formfields("Text1").Result = Textbox1.Text
  .Formfields("Text2").Result = Textbox2.Text
  .Formfields("Text3").Result = Textbox3.Text
End With
End Sub

So the user entered 1 and 2, leaving 3 blank. They open it again, and 1 and 2 on the userform will be the previously entered text. Pressing OK will simply put it back in again.

If you are using real bookmarks (NOT formfields) it is a little trickier but quite do-able. You have to make sure the Range of the bookmarks includes the text - both back and forth.


Gerry
My paintings and sculpture
 
Thanks to all. I am using bookmarks.

So for instance, my code currently looks like this:

Code:
' Form name is Eastern
Private Sub CommandButton1_Click()
    ActiveDocument.FormFields("text1").Result = Eastern.TXTcurrentweekEastern.Value
    ActiveDocument.FormFields("text171").Result = Eastern.TXTcurrentweekEastern.Value
    ActiveDocument.FormFields("text19").Result = Eastern.TXTcurrentweekEastern.Value
    ActiveDocument.FormFields("text2").Result = Eastern.TXTpreviousperiodEastern.Value
    ActiveDocument.FormFields("text29").Result = Eastern.TXTpreviousperiodEastern.Value
    ActiveDocument.FormFields("text3").Result = Eastern.TXTcwpastdueEastern.Value
    ActiveDocument.FormFields("text24").Result = Eastern.TXTcwpastdueEastern.Value
    ActiveDocument.FormFields("text7").Result = Eastern.TXTcwccanEastern.Value
    ActiveDocument.FormFields("text23").Result = Eastern.TXTcwccanEastern.Value
    ActiveDocument.FormFields("text11").Result = Eastern.TXTpppastdueEastern.Value
    ActiveDocument.FormFields("text15").Result = Eastern.TXTppccanEastern.Value
    ActiveDocument.FormFields("text32").Result = Eastern.TXTdealer1Eastern.Value
    ActiveDocument.FormFields("text33").Result = Eastern.TXTcustomer1Eastern.Value
    ActiveDocument.FormFields("text34").Result = Eastern.TXTccan1Eastern.Value
    ActiveDocument.FormFields("text35").Result = Eastern.TXTamount1Eastern.Value
    
    ActiveDocument.Unprotect
    ActiveDocument.FormFields("Text36").Range.Fields(1).Result.Text = Eastern.TXTdetails1Eastern.Value
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Me.Hide
End Sub
Private Sub UserForm_Click()

End Sub

This data is going into bookmarks on the word document. Looking at the code you supplied, how would I achieve this with bookmarks considering the code I have attached?

Thanks!
 
Furthermore, where do I place the code? In a Module or in the form called "EASTERN" itself along with the other code I have displayed?
 
Thanks to all. I am using bookmarks.
No, you are not. You are using formfields.

Just like I posted, but the other way.
Code:
Sub Eastern_Initialize()
  Eastern.TXTcurrentweekEastern.Value = _
     ActiveDocument.FormFields("text1").Result
  Eastern.TXTcurrentweekEastern.Value = _
     ActiveDocument.FormFields("text171").Result
' etc etc.
End Sub
The textboxes on the userform are filled with the formfield values.

BTW: even though it is a pain in the butt, it is better to NOT keep the default names of the formfields - text1, text171 etc.

These names are NOT set to the formfield. They are set to order in the document.

If you ever move Text1 to after Text2, it will automatically have its name changed to Text2. Word will NOT tell you this. If they are explicitly named, the name stays with it.

Gerry
My paintings and sculpture
 
Thanks greatly fumei. Two small questions.

1.) Do I use the example you provided at the top where I have the IF statement or do I use your second statement for my purpose?

2.) I have a module called AutoOpen() and I have 6 forms, one being RegionList that allows you to pick the next form to open, which would subsequently open the EASTERN form if that was chose. With that said, where do I place this Sub Eastern_Initialize() and the subsequent code in order for it to populate the EASTERN userform back with the data populated in the word document?
 
With that said, where do I place this Sub Eastern_Initialize() and the subsequent code in order for it to populate the EASTERN userform back with the data populated in the word document?
Please read your own quote above along with thename of the procedure....

Eastern_Initialize

where would you think that may be?
1.) Do I use the example you provided at the top where I have the IF statement or do I use your second statement for my purpose?
I am not following this.

You can use the IF - that is if I know what IF you are talking about - or not. The IF just checked to see if the formfield result was "", or blank. You could skip that and simply transfer whatever it is to the textbox to the userform. It does not matter if it is blank or not.

If it is blank - the textbox is blank
If it is not blank - the textbox is that text.

So really, you do not need the If, that is, is you want the textbox on the userform to equal the text in the formfield.

As for first vs second...ummmm. Not sure what you are asking.

Let me try again.

The userform initialize event...which BTW is an event of the form, the one that intializes it...gets the text from the formfields.

userform textbox.text = activedoc.formfield result

The commandbutton on the userform does the reverse - it puts the textbox text into the formfields.

activedoc.formfield result = userform textbox.text

You have six userforms[/b]! Hmmmmmm. I don't know what you are dealing with, but in my experience that sounds
excessive.

Why are you using AutoOpen()?

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top