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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating Form Entry - Assistance from the masters, please.

Status
Not open for further replies.

Waraq

Programmer
May 8, 2001
26
US
Hi All. I hope that you can help me. I am automating the entry of data to be popped into a template and I am using a combination of Field code, you know the stuff inside { } and VB. I am wondering a couple of things:
1) I am trying to do a calculation on the form. Basically if the numberUsers is a certain value, I need to calculate with different rates. Here is the rate table:
[ul][li]# Users monthly per user[/li]
[li]Up to 50 $150 n/a [/li]
[li]51-5,000 $2.50 [/li]
[li]5,001-10,000 $2.00 [/li]
[li]10,001+ $1.50 [/li][/ul]
The formula I am using is:
Code:
{IF {numberUsers}=< 50 150 &quot;{ IF { = AND ( { COMPARE { numberUsers } > 50 }, { COMPARE { numberUsers } <= 5000 } ) } = 1 numberUsers*2.50 &quot;{ IF { = AND ( { COMPARE { numberUsers } > 5000 }, { COMPARE { numberUsers } <= 10000 } ) } = 1 numberUsers*2 numberUsers*1.50}&quot;}&quot; \# &quot;$#,##0.00;($#,##0.00)}

2) I get number of users and other values by using the VB code below - I don't know if there is an easier way, I need user input for it:
Note: there are {REF bookmarks} throughout the form to capture the date entered.

Code:
Private Sub Document_New()
Dim bkm As Bookmark
Dim rngTemp As Range
Dim strTemp As String


Set rngTemp = ActiveDocument.Range(Start:=0, End:=0)
    
'Set Company Name
'MsgBox &quot;begin Set Company Name&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;companyName&quot;, ValueText:=InputBox(&quot;Please enter the Company Name:&quot;, &quot;Company Name&quot;)
Selection.Collapse Direction:=wdCollapseEnd

'Set Contact Name
'MsgBox &quot;begin Set Contact Name&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;contactName&quot;, ValueText:=InputBox(&quot;Please enter the Contact Name:&quot;, &quot;Contact Name&quot;)
Selection.Collapse Direction:=wdCollapseEnd

'Set Contact Title
'MsgBox &quot;begin Set Contact Title&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;contactTitle&quot;, ValueText:=InputBox(&quot;Please enter the Contact's Title:&quot;, &quot;Contact Title&quot;)
Selection.Collapse Direction:=wdCollapseEnd

'Set Number Of Users
'MsgBox &quot;begin Set Num Users&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;numberUsers&quot;, ValueText:=InputBox(&quot;Please enter the Number of Users:&quot;, &quot;# of Users&quot;)
Selection.Collapse Direction:=wdCollapseEnd

'Set Fixed Price
'MsgBox &quot;begin Set Fixed Price&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;fixedPrice&quot;, ValueText:=InputBox(&quot;Please enter the fixed price of the deal:&quot; _
    & Chr(13) & Chr(10) & &quot;i.e. 15000&quot;, &quot;Deal Price&quot;, &quot;15000&quot;)
Selection.Collapse Direction:=wdCollapseEnd

'Set License Price
'MsgBox &quot;begin Set License Price&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;licensePrice&quot;, ValueText:=InputBox(&quot;Please enter the price of each license:&quot; _
    & Chr(13) & Chr(10) & &quot;i.e. 60&quot;, &quot;License Price&quot;, &quot;60&quot;)
Selection.Collapse Direction:=wdCollapseEnd

'Set Support Price
'MsgBox &quot;begin Set Support Price&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;supportPrice&quot;, ValueText:=InputBox(&quot;Please enter the price of support:&quot; _
    & Chr(13) & Chr(10) & &quot;i.e. 15&quot;, &quot;License Price&quot;, &quot;15&quot;)
Selection.Collapse Direction:=wdCollapseEnd

'Set Kickoff date
'MsgBox &quot;begin Set KickOff Date&quot;
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:=&quot;kickoffDate&quot;, ValueText:=InputBox(&quot;Please enter the estimated Kick-Off Date:&quot; _
    & Chr(13) & Chr(10) & &quot;i.e. January 1, 2004&quot;, &quot;Kickoff Date&quot;, &quot;January 1, 2004&quot;)
Selection.Collapse Direction:=wdCollapseEnd
    
ActiveDocument.Fields.Update
 
End Sub

3) The final piece is that I ask the user for a paragraph to personalize the document, didn't know how to do this in VB so I did it with a Form ASK statement
Code:
{ASK Notes “Please enter any notes pertaining to the customer:” \d &quot;Mercury Technologies had the chance to speak with you about your infrastructure and we …&quot;}

Thanks in advance for any help that you can lend.

 
Might be able to help a bit. I think you can simplify your formula by using a lookup table and formula =VLOOKUP( ..., TRUE).

so the 2 column table would be something like :-
0 0
51 2.50
5,001 2.00
10,001 1.50
100,000 1.50

and the formula :-
=VLOOKUP(A8,$A$1:$B$5,2,TRUE)



Regards
BrianB
** Let us know if you get something that works !
================================
 
Sorry I think that there was a misunderstanding...the rate table doesn't exist in the document; are you suggesting that I add it to it. Also, this is in Word.

Thanks.
 
Ooops. Sorry - didn't read your post properly.

Regards
BrianB
Use CupOfCoffee to speed up all windows applications
================================
 
BrianB,

That ok, you seem to be the only one who does [2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top