PDA

View Full Version : Field codes to automate document - may need VBA



gwh
03-14-2008, 04:15 PM
Hi everyone,

I'm trying to automate a proposal document by using field codes. I'm basically using the Fillin field, eg. {FILLIN "ENTER THE NAME OF THE PROPOSAL" \* MERGEFORMAT} to prompt the user for information. If this information is used elsewhere in the document, I've inserted {REF Name_of_Proposal } at each particular point. I also bookmarked the name of the fields that would be populating the other fields as described above, in order to get it working.

The problem is that there's a page in the document where there's a table with two columns - milestone and date. As part of the automation process, I need to create a fillin box for both the milestone and date cells. This is no problem as it'd just work like all the other fillins and the information would populate the cell under "milestone" and the cell under "date". The thing is that there may be more than one row in the table, ie. a necessity to create more than one milestone and date pair. I thought about creating separate fillins labelled milestone1, date1, then milestone2, date2, but I don't know in advance how many of these rows there will be - in fact it will vary for each proposal. So I wondered if someone could tell me if there's any field codes I could use to allow the user to enter all the information needed in the one fillin box but have the ability to somehow separate the different milestone/date pairs that would then get populated consecutively into different table rows. Is this beyond the capabilities of field codes or would I have to use VBA to accomplish this? If VBA is required can someone tell me where I could get some code that would do this, as my knowledge of VBA is very limited.

My other issue is that I'd like a message box to pop-up before a particular fillin dialogue appears. This is because there's a section in the proposal where helpful instructions need to be given to the user before filling in the dialogue. Is there a way to incorporate such a pop-up and customise it so that it appears in the correct place? Would VBA be needed for this also?

Appreciate any help offered.

fumei
03-15-2008, 05:05 PM
This sounds like you could use a userform.

As for multiple rows, if you do not know in advance how many fill-ins, how do you know how many rows there are?

Regarding a message box before a specific fill-in, no, I do not think so. Again, this may be calling for a userform where you could have all sorts of messages/help.

gwh
03-16-2008, 05:05 AM
Thanks for the reply,

I decided to try userforms as you suggested. As this is my first try at VBA coding I'm getting a couple of run-time errors when I test my code. To begin with, I've basically just set up a multi-page form with two input text boxes on the first page and about 7 of the boxes on the second page. I'm trying to see if I can get the information into the Word document via the bookmarks, then once I get it right I'll tackle the bigger problem of inserting the information into a table, so I wondered if you could help me troubleshoot at this stage. I receive this error when I test and try and click the 'clear' button:

Runtime error '424' object required

...and I'm getting this error when I try to press the "Ok" button:

Run-time error '5941' The requested member of the collection does not exist.


Can you see any obvious errors in my code that would cause these problems?


Private Sub cmdClear_Click()
txtClient_Company_Name.Value = Null
txtClient_Contact_Name.Value = Null
txtClient_Position.Value = Null
txtClient_Title_Description.Value = Null
txtCompany_Description.Value = Null
txtCompany_PM_Name.Value = Null
txtCompany_Title_Description.Value = Null
txtName_of_Proposal.Value = Null
txtCustomer_Name.Value = Null
End Sub



Private Sub cmdOk_Click()
Application.ScreenUpdating = False
With ActiveDocument
.Bookmarks("Client_Company_Name").Range.Text = txtClient_Company_Name.Value
.Bookmarks("Client_Contact_Name").Range.Text = txtClient_Contact_Name.Value
.Bookmarks("Client_Position").Range.Text = txtClient_Position.Value
.Bookmarks("Client_Title_Description").Range.Text = txtClient_Title_Description.Value
.Bookmarks("Company_Description").Range.Text = txtCompany_Description.Value
.Bookmarks("Company_PM_Name").Range.Text = txtCompany_PM_Name.Value
.Bookmarks("Energetics_Title_Description").Range.Text = txtEnergetics_Title_Description.Value
.Bookmarks("Name_of_Proposal").Range.Text = txtName_of_Proposal.Value
.Bookmarks("Customer_Name").Range.Text = txtCustomer_Name.Value
End With
Application.ScreenUpdating = True
Unload Me
End Sub

Private Sub cmdCancel_Click()
Unload Me
ActiveDocument.Close SaveChanges:=False
End Sub

fumei
03-16-2008, 07:52 PM
Please, you are cross-posting. You have the exact same question going on at Tek-Tips. These things should be mentioned.