UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Update Merge Field Depending On Entry In Text Box, Office 2013    
 
   
davideyles
post Apr 30 2020, 04:15 AM
Post#1



Posts: 217
Joined: 13-April 03
From: Cornwall, UK


Hi all
Might be going round this the wrong way but here goes

I have a document that I need to print with each consignment of animals I send. What I have tried to do is to automate the process by having the form filled out in word with auto updating of dates etc and have just added a macro to run on opening of the document ask for the number of animals.

ActiveDocument.FormFields("NumberOfLambs").Result = InputBox("Enter number of lambs")

This works fine, but what I would like to do is after the Text Box Field have the word lamb or lambs depending on the number on the form.

I have added a merge field with the IF function

IF NumberOfLambs>1,"Lambs","Lamb" \* MERGEFORMAT \* MERGEFORMAT

but I can't get it to change to 1 Lamb or 2 Lambs

What am I doing wrong?

David
Go to the top of the page
 
dashiellx2000
post Apr 30 2020, 09:19 AM
Post#2


UtterAccess VIP
Posts: 9,864
Joined: 11-March 05
From: Maryland


You need to evaluate the inputbox return before setting the form's field.

Something like:

Dim x as integer

x = InputBox("Enter number of lambs")

If x = 1 then
ActiveDocument.FormFields("NumberOfLambs").Result = x & " lamb"
Else
ActiveDocument.FormFields("NumberOfLambs").Result = x & " lambs"
End if

hth

--------------------
William
“We're run by the Pentagon, we're run by Madison Avenue, we're run by television, and as long as we accept those things and don't revolt we'll have to go along with the stream to the eventual avalanche"
Go to the top of the page
 
davideyles
post Apr 30 2020, 09:56 AM
Post#3



Posts: 217
Joined: 13-April 03
From: Cornwall, UK


Ideal thumbup.gif . Thank you very much.


David
Go to the top of the page
 
davideyles
post Apr 30 2020, 10:17 AM
Post#4



Posts: 217
Joined: 13-April 03
From: Cornwall, UK


Hi
Just adding to the macro a little more, it is now like this.

Private Sub Document_Open()
Dim x As Integer

x = InputBox("Enter number of lambs")

If x = 1 Then
ActiveDocument.FormFields("NumberOfLambs").Result = x & " lamb"
Else
ActiveDocument.FormFields("NumberOfLambs").Result = x & " lambs"
End If

ActiveDocument.PrintOut

'Application.Quit SaveChanges:=wdDoNotSaveChanges


End Sub

When I remove the "apostrophe" on the last line (in red), the print (in blue) doesn't happen. Is that because the Application.Quit happens before the document has finished spooling? Do I need a delay of some sort?


David
Go to the top of the page
 
dashiellx2000
post Apr 30 2020, 10:21 AM
Post#5


UtterAccess VIP
Posts: 9,864
Joined: 11-March 05
From: Maryland


To be honest, Word isn't my area of expertise, but I would suggest that you create a new post for that question since it is separate from your previous one. Someone will more knowledge about event timing in Work can help better.

Did the evaluation work for getting your form's field set correctly?

--------------------
William
“We're run by the Pentagon, we're run by Madison Avenue, we're run by television, and as long as we accept those things and don't revolt we'll have to go along with the stream to the eventual avalanche"
Go to the top of the page
 
davideyles
post Apr 30 2020, 11:02 AM
Post#6



Posts: 217
Joined: 13-April 03
From: Cornwall, UK


Found out it was due to background printing in Word


added

ActiveDocument.PrintOut Background:=False

and problem solved! guiness.gif

David
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    3rd July 2020 - 08:49 AM