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!

MS Word forms not printing if no data

Status
Not open for further replies.

jeffmoore

Programmer
Joined
Aug 29, 2003
Messages
301
Location
US
I have been asked to create a variable length form in Word. It will look something like this;

Part# product code qty <<< header
123 456 69 <<< line 1 data
321 654 96 <<< line 2 data
: : :
999 666 77 <<< line N data

I need to give the user of the form up to 30 places to enter data (as above).Thats the easy part.. just make 30 form rows. BUT I dont want the empty rows to print..

Any Ideas .... I could do this in excell too.. but am not real familliar with the form process in word or excell ... I do know access thou..
TIA
Jeff
 
Well, I'd do it this way:

Give your text boxes consistent names so that the ones on line 7, for instance, are called something like txt7Part, txt7ProdCode and so on;
Add some code to your print function that checks each line to determine whether all the text boxes on it are empty;
If they're all empty set their 'visible' properties to false.

A function something like this would probably work (you'd need to add bits for the other columns though):

Code:
Private Sub PrintCheck()
    
    Dim intRow As Integer  ' Current row being checked
    Dim strRow As String   ' String version of row number
    
    For intRow = 1 To 30
        
        strRow = CStr(intRow)
        
        If Controls(&quot;txt&quot; & strRow & &quot;Part&quot;).Text = &quot;&quot; And _
            Controls(&quot;txt&quot; & strRow & &quot;ProdCode&quot;).Text = &quot;&quot; Then
            
            Controls(&quot;txt&quot; & strRow & &quot;Part&quot;).Visible = False
            Controls(&quot;txt&quot; & strRow & &quot;ProdCode&quot;).Visible = False
            
        End If
        
    Next intRow
    
    Me.PrintForm
    
End Sub

There are probably much tidier ways of doing this!



Nelviticus
 
Just want to point out that Me.PrintForm sends a bitmap image to the printer. An image of the VBA form in focus. Which could all you want, but if you want to actually KEEP the information on the form, you are going to have to get that data into the actual document.

 
Thanks for the help. And no I dont need to keep the info, just print it or email it.
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top