Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
I have created a User Form that runs when the document opens that propmts for
data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
#2
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
In the Userform_Activate() procedure of the userform, you must create
code that gets the values of the bookmarks and puts those values into the controls of the userform. This procedure runs just before the userform appears on the screen. For example, if you have a bookmark named "Address" in the document, and a corresponding text box control named "tbxAddress" in the userform, the Userform_Activate() procedure should include the line tbxAddress.Text = ActiveDocument.Bookmarks("Address").Range.Text You can use similar code to initialize check boxes, list boxes, and other controls in the userform from data in the document. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. On Sun, 7 Jan 2007 17:31:00 -0800, Michael wrote: I have created a User Form that runs when the document opens that propmts for data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
#3
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
I would suggest that you use DocVariable fields instead of bookmarks as all
you need to do then is load the controls on the form with the values in the document variables and replacing the data in the document is easier with DocVariables rather than bookmarks as you will probably need code to re-create the bookmark if you change the data that is in it. -- 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 "Michael" wrote in message ... I have created a User Form that runs when the document opens that propmts for data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
#4
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
Sounds great. How to do using UserForms?
"Doug Robbins - Word MVP" wrote: I would suggest that you use DocVariable fields instead of bookmarks as all you need to do then is load the controls on the form with the values in the document variables and replacing the data in the document is easier with DocVariables rather than bookmarks as you will probably need code to re-create the bookmark if you change the data that is in it. -- 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 "Michael" wrote in message ... I have created a User Form that runs when the document opens that propmts for data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
#5
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
Here's the code from a userform that uses that approach to enter the
information into the document and to load it back into the userform if the form is run once again Private Sub CommandButton1_Click() With ActiveDocument If txtCompany = "" Then .Variables("Company").Value = " " Else .Variables("Company").Value = txtCompany End If If txtProject = "" Then .Variables("Project").Value = " " Else .Variables("Project").Value = txtProject End If If txtDocNum = "" Then .Variables("DocNum").Value = " " Else .Variables("DocNum").Value = txtDocNum End If If txtRevNum = "" Then .Variables("Revision").Value = " " Else .Variables("Revision").Value = txtRevNum End If If txtDocTitle = "" Then .Variables("DocTitle").Value = " " Else .Variables("DocTitle").Value = txtDocTitle End If .Fields.Update .Sections(1).Headers(wdHeaderFooterPrimary).Range. Fields.Update .Bookmarks("Text").Range.Select End With Unload Me End Sub Private Sub UserForm_Initialize() With ActiveDocument txtCompany = .Variables("Company").Value txtProject = .Variables("Project").Value txtDocNum = .Variables("DocNum").Value txtRevNum = .Variables("Revision").Value txtDocTitle = .Variables("DocTitle").Value End With txtDocNum.SetFocus End Sub -- 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 "Michael" wrote in message ... Sounds great. How to do using UserForms? "Doug Robbins - Word MVP" wrote: I would suggest that you use DocVariable fields instead of bookmarks as all you need to do then is load the controls on the form with the values in the document variables and replacing the data in the document is easier with DocVariables rather than bookmarks as you will probably need code to re-create the bookmark if you change the data that is in it. -- 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 "Michael" wrote in message ... I have created a User Form that runs when the document opens that propmts for data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
#6
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
Hi Doug,
Thanks for your help. I have inserted DocVariable fields in the document and copied the code below into VB so it reads as follows: Private Sub Cancel_Click() UserForm1.Hide End Sub Private Sub Image1_Click() End Sub Private Sub OK_Click() With ActiveDocument If txtComp = "" Then .Variables("Company").Value = " " Else .Variables("Company").Value = txtComp End If If txtAtt = "" Then .Variables("Attention").Value = " " Else .Variables("Attention").Value = txtAtt End If If txtFax = "" Then .Variables("FaxNo").Value = " " Else .Variables("FaxNo").Value = txtFax End If If txtDay = "" Then .Variables("Date").Value = " " Else .Variables("Date").Value = txtDay End If If txtPages = "" Then .Variables("NoPages").Value = " " Else .Variables("NoPages").Value = txtPages End If If txtTopic = "" Then .Variables("Subject").Value = " " Else .Variables("Subject").Value = txtTopic End If .Fields.Update End With Unload Me End Sub Private Sub UserForm_Click() With ActiveDocument txtComp = .Variables("Company").Value txtAtt = .Variables("Attention").Value txtFax = .Variables("FaxNo").Value txtDay = .Variables("Date").Value txtPages = .Variables("NoPages").Value txtTopic = .Variables("Subject").Value End With End Sub When the UserForm runs a balnk space is entered into the DocVariable field rather than the text I enter into the text boxes. Any ideas why this might be happening? Thanks, Mike. "Doug Robbins - Word MVP" wrote: Here's the code from a userform that uses that approach to enter the information into the document and to load it back into the userform if the form is run once again Private Sub CommandButton1_Click() With ActiveDocument If txtCompany = "" Then .Variables("Company").Value = " " Else .Variables("Company").Value = txtCompany End If If txtProject = "" Then .Variables("Project").Value = " " Else .Variables("Project").Value = txtProject End If If txtDocNum = "" Then .Variables("DocNum").Value = " " Else .Variables("DocNum").Value = txtDocNum End If If txtRevNum = "" Then .Variables("Revision").Value = " " Else .Variables("Revision").Value = txtRevNum End If If txtDocTitle = "" Then .Variables("DocTitle").Value = " " Else .Variables("DocTitle").Value = txtDocTitle End If .Fields.Update .Sections(1).Headers(wdHeaderFooterPrimary).Range. Fields.Update .Bookmarks("Text").Range.Select End With Unload Me End Sub Private Sub UserForm_Initialize() With ActiveDocument txtCompany = .Variables("Company").Value txtProject = .Variables("Project").Value txtDocNum = .Variables("DocNum").Value txtRevNum = .Variables("Revision").Value txtDocTitle = .Variables("DocTitle").Value End With txtDocNum.SetFocus End Sub -- 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 "Michael" wrote in message ... Sounds great. How to do using UserForms? "Doug Robbins - Word MVP" wrote: I would suggest that you use DocVariable fields instead of bookmarks as all you need to do then is load the controls on the form with the values in the document variables and replacing the data in the document is easier with DocVariables rather than bookmarks as you will probably need code to re-create the bookmark if you change the data that is in it. -- 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 "Michael" wrote in message ... I have created a User Form that runs when the document opens that propmts for data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
#7
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
Are you sure that the names of the controls on the form are identical to
what the code is expecting: For example, ..Variables("Company").Value = txtComp is there a control named txtComp? In the code, if you insert a period after txtComp, the intellisense should give you a list of attributes to choose. The one that you want is the .Text one which is the default. If the list doesn't appear, then the name used in the code is not the name of a control on your form. -- 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 "Michael" wrote in message news Hi Doug, Thanks for your help. I have inserted DocVariable fields in the document and copied the code below into VB so it reads as follows: Private Sub Cancel_Click() UserForm1.Hide End Sub Private Sub Image1_Click() End Sub Private Sub OK_Click() With ActiveDocument If txtComp = "" Then .Variables("Company").Value = " " Else .Variables("Company").Value = txtComp End If If txtAtt = "" Then .Variables("Attention").Value = " " Else .Variables("Attention").Value = txtAtt End If If txtFax = "" Then .Variables("FaxNo").Value = " " Else .Variables("FaxNo").Value = txtFax End If If txtDay = "" Then .Variables("Date").Value = " " Else .Variables("Date").Value = txtDay End If If txtPages = "" Then .Variables("NoPages").Value = " " Else .Variables("NoPages").Value = txtPages End If If txtTopic = "" Then .Variables("Subject").Value = " " Else .Variables("Subject").Value = txtTopic End If .Fields.Update End With Unload Me End Sub Private Sub UserForm_Click() With ActiveDocument txtComp = .Variables("Company").Value txtAtt = .Variables("Attention").Value txtFax = .Variables("FaxNo").Value txtDay = .Variables("Date").Value txtPages = .Variables("NoPages").Value txtTopic = .Variables("Subject").Value End With End Sub When the UserForm runs a balnk space is entered into the DocVariable field rather than the text I enter into the text boxes. Any ideas why this might be happening? Thanks, Mike. "Doug Robbins - Word MVP" wrote: Here's the code from a userform that uses that approach to enter the information into the document and to load it back into the userform if the form is run once again Private Sub CommandButton1_Click() With ActiveDocument If txtCompany = "" Then .Variables("Company").Value = " " Else .Variables("Company").Value = txtCompany End If If txtProject = "" Then .Variables("Project").Value = " " Else .Variables("Project").Value = txtProject End If If txtDocNum = "" Then .Variables("DocNum").Value = " " Else .Variables("DocNum").Value = txtDocNum End If If txtRevNum = "" Then .Variables("Revision").Value = " " Else .Variables("Revision").Value = txtRevNum End If If txtDocTitle = "" Then .Variables("DocTitle").Value = " " Else .Variables("DocTitle").Value = txtDocTitle End If .Fields.Update .Sections(1).Headers(wdHeaderFooterPrimary).Range. Fields.Update .Bookmarks("Text").Range.Select End With Unload Me End Sub Private Sub UserForm_Initialize() With ActiveDocument txtCompany = .Variables("Company").Value txtProject = .Variables("Project").Value txtDocNum = .Variables("DocNum").Value txtRevNum = .Variables("Revision").Value txtDocTitle = .Variables("DocTitle").Value End With txtDocNum.SetFocus End Sub -- 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 "Michael" wrote in message ... Sounds great. How to do using UserForms? "Doug Robbins - Word MVP" wrote: I would suggest that you use DocVariable fields instead of bookmarks as all you need to do then is load the controls on the form with the values in the document variables and replacing the data in the document is easier with DocVariables rather than bookmarks as you will probably need code to re-create the bookmark if you change the data that is in it. -- 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 "Michael" wrote in message ... I have created a User Form that runs when the document opens that propmts for data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
#8
Posted to microsoft.public.word.newusers
|
|||
|
|||
User Forms
BTW, the reason for using the If...then...Else... construction is to load
the variable with a space if the user does not enter anything into the control on the user form. Without that, the variable would not be created and then an error would occur if there was an attempt to get the values from the variables to appear in the userform. -- 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 "Michael" wrote in message news Hi Doug, Thanks for your help. I have inserted DocVariable fields in the document and copied the code below into VB so it reads as follows: Private Sub Cancel_Click() UserForm1.Hide End Sub Private Sub Image1_Click() End Sub Private Sub OK_Click() With ActiveDocument If txtComp = "" Then .Variables("Company").Value = " " Else .Variables("Company").Value = txtComp End If If txtAtt = "" Then .Variables("Attention").Value = " " Else .Variables("Attention").Value = txtAtt End If If txtFax = "" Then .Variables("FaxNo").Value = " " Else .Variables("FaxNo").Value = txtFax End If If txtDay = "" Then .Variables("Date").Value = " " Else .Variables("Date").Value = txtDay End If If txtPages = "" Then .Variables("NoPages").Value = " " Else .Variables("NoPages").Value = txtPages End If If txtTopic = "" Then .Variables("Subject").Value = " " Else .Variables("Subject").Value = txtTopic End If .Fields.Update End With Unload Me End Sub Private Sub UserForm_Click() With ActiveDocument txtComp = .Variables("Company").Value txtAtt = .Variables("Attention").Value txtFax = .Variables("FaxNo").Value txtDay = .Variables("Date").Value txtPages = .Variables("NoPages").Value txtTopic = .Variables("Subject").Value End With End Sub When the UserForm runs a balnk space is entered into the DocVariable field rather than the text I enter into the text boxes. Any ideas why this might be happening? Thanks, Mike. "Doug Robbins - Word MVP" wrote: Here's the code from a userform that uses that approach to enter the information into the document and to load it back into the userform if the form is run once again Private Sub CommandButton1_Click() With ActiveDocument If txtCompany = "" Then .Variables("Company").Value = " " Else .Variables("Company").Value = txtCompany End If If txtProject = "" Then .Variables("Project").Value = " " Else .Variables("Project").Value = txtProject End If If txtDocNum = "" Then .Variables("DocNum").Value = " " Else .Variables("DocNum").Value = txtDocNum End If If txtRevNum = "" Then .Variables("Revision").Value = " " Else .Variables("Revision").Value = txtRevNum End If If txtDocTitle = "" Then .Variables("DocTitle").Value = " " Else .Variables("DocTitle").Value = txtDocTitle End If .Fields.Update .Sections(1).Headers(wdHeaderFooterPrimary).Range. Fields.Update .Bookmarks("Text").Range.Select End With Unload Me End Sub Private Sub UserForm_Initialize() With ActiveDocument txtCompany = .Variables("Company").Value txtProject = .Variables("Project").Value txtDocNum = .Variables("DocNum").Value txtRevNum = .Variables("Revision").Value txtDocTitle = .Variables("DocTitle").Value End With txtDocNum.SetFocus End Sub -- 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 "Michael" wrote in message ... Sounds great. How to do using UserForms? "Doug Robbins - Word MVP" wrote: I would suggest that you use DocVariable fields instead of bookmarks as all you need to do then is load the controls on the form with the values in the document variables and replacing the data in the document is easier with DocVariables rather than bookmarks as you will probably need code to re-create the bookmark if you change the data that is in it. -- 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 "Michael" wrote in message ... I have created a User Form that runs when the document opens that propmts for data to be entered. This data is then attributed to bookmarks within the document. I have created a macro that recalls the User Form so that I can change data is necessary, however when the User Form is recalled it is blank and does not recognise the previously inserted information. How do I fix this? |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Forms w/blank spaces for user to fill in? | Microsoft Word Help | |||
Detach or change SQL data source for Word template, and other Qs | Mailmerge | |||
Validating Forms in MS Word | Microsoft Word Help | |||
User Forms and Combo boxes in Work | Microsoft Word Help | |||
How do I share ALL files with new user? | Microsoft Word Help |