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

vba question 3

Status
Not open for further replies.

Palmyra

Programmer
Jan 5, 2007
150
US
I'm outputing a text file that is used as a source file to print a label. The below code prevents empty strings from printing on lines where there's no data. However, if there's no data, then that row is skipped. So that if there was only data for me.txtlabel3, then me.txtlabel3 would print on line 1.

I want Me.txtLabel1 on line 1; Me.txtLabel2 on line 2; Me.txtLabel3 on line 3 etc.

Any ideas?

Thanks.

Open DestinationFolder & "Labels.txt" For Output As #1

If Len(Me.txtLabel1.Text) > 0 Then
Print #1, Me.txtLabel1
End If

If Len(Me.txtLabel2.Text) > 0 Then
Print #1, Me.txtLabel2
End If

If Len(Me.txtlabel3.Text) > 0 Then
Print #1, Me.txtlabel3
End If

If Len(Me.txtLabel4.Text) > 0 Then
Print #1, Me.txtLabel4
End If

If Len(Me.txtLabel5.Text) > 0 Then
Print #1, Me.txtLabel5
End If

If Len(Me.txtLabel6.Text) > 0 Then
Print #1, Me.txtLabel6
End If

Close #1
 


Hi,

Use other variables for the Print Line values.

If any textbox is empty, just move on to the next one, until you have a value for that line or print.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sounds right, but I'm kind of lost on how to accomplish that.

Actually, I thought that's what I was doing.

Thanks.
 
I want Me.txtLabel1 on line 1; Me.txtLabel2 on line 2; Me.txtLabel3 on line 3 etc.
So, you wanted just this ?
Code:
Open DestinationFolder & "Labels.txt" For Output As #1
Print #1, Me.txtLabel1 & ""
Print #1, Me.txtLabel2 & ""
Print #1, Me.txtLabel3 & ""
Print #1, Me.txtLabel4 & ""
Print #1, Me.txtLabel5 & ""
Print #1, Me.txtLabel6 & ""
Close #1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I my code below, I'm checking for the existence of anything in a text box and if there's something there, output it. What I want to happen is that if there's nothing in a text box, advance to the next line, and check the next text box.

In the below code, if text box 1 is empty, nothing is output into line 1, but then if there's something in line 2, it prints in line 1.

Empty strings are causing me problems. I can advance a line with vbcrlf, but I get an empty string.

Maybe I can't handle the problem in this code.

Thanks.

If Len(Me.txtLabel1.Text) > 0 Then
Print #1, Me.txtLabel1
End If

If Len(Me.txtLabel2.Text) > 0 Then
Print #1, Me.txtLabel2
End If

If Len(Me.txtlabel3.Text) > 0 Then
Print #1, Me.txtlabel3
End If

If Len(Me.txtLabel4.Text) > 0 Then
Print #1, Me.txtLabel4
End If

If Len(Me.txtLabel5.Text) > 0 Then
Print #1, Me.txtLabel5
End If

If Len(Me.txtLabel6.Text) > 0 Then
Print #1, Me.txtLabel6
End If

 
Did you try my suggestion ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 


Just out of curiosity, why do you have your variables as LABELS?

Do you REALLY have text is these LABELS?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
In the below code, if text box 1 is empty, nothing is output into line 1, but then if there's something in line 2, it prints in line 1.Empty strings are causing me problems.
I can advance a line with vbcrlf, but I get an empty string.
These 2 statements seeem contradictory to me. You say that if box 1 is empty, you want the next box on the next line, not line 1. Which will result in an empty string (and a linefeed)

Wouldn't this be what you want?

If Len(Me.txtLabel1.Text) > 0 Then
Print #1, Me.txtLabel1
Else
' Print your linefeed here
End If
 
PHV, Yes, I did try your suggestion

Skip, I probably shouldn't call text boxes labels. I'm printing labels - that's why I did it.

Here's what I was trying to do:

We have software that prints labels (the kind that get stuck on file folders in law firms). I'm creating a source file for that software to use. I output a source file with six rows of data that the label software uses to print a six-up sheet of labels. Everything is fine. There are six text boxes in the application where they key the data. If they key into position 1 and 2, data prints on labels 1 and 2. If they key into position 3, data prints on label 3. It's a way to save labels.

Now the users want 'tic' marks on the label that they can use as a guide to fold the labels in half.

So now, if the source file has only one row of data, the 'tic' marks show up on the other five blank labels - I guess because of empty strings. I was able to handle this in the vba code above. Except - that if they keyed data into position 1 and position 3, instead of printing on label 1 and label 3, the data was on line 1 and 2.

But in the end, the tech support for the label printing software came up with a way to handle the problem in their software.

So, thank you for trying and sorry for the confusing post.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top