This works, this doesn't

M

MikeB

This Debug.Print statement works perfectly.

'Debug.Print "Game(" & strGameNumber & ")" _
; Tab(12); "Match(" & strmatchNumber & ")" _
; Tab(25); "White:" & "(" & strWhiteId & ")" _
; White.Fname & " " & White.Lname _
; "(" & White.Rating & ")" & " Games(" & White.Games
& ")" _
; Tab(70); "Black:" & "(" & strBlackId & ")" _
; Black.Fname & " " & Black.Lname _
; "(" & Black.Rating & ")" & "Games(" & Black.Games &
")" _
; dblWhiteScore, dblBlackScore

I have a routing that is trying to write the same data to a file:

Sub prStr(ByVal indent As Long, ByVal str As String)
intLineCounter = intLineCounter + 1
Print #1, Time(), String(indent, "-") & str
If (intLineCounter Mod 100) = 0 Then
Debug.Print "Printing line " & intLineCounter & " at " & Now()
End If
End Sub

But I'm getting a compile error (various, depending on exactly what
I'm trying at the time when I do this:

prStr intNestLevel, "Game(" & strGameNumber & ")" _
; Tab(12); "Match(" & strmatchNumber & ")"
' Tab(25); "White:" & "(" & strWhiteId & ")" & _
' White.Fname & " " & White.Lname & _
' "(" & White.Rating & ")" & " Games(" & White.Games
& ")" & _
' Tab(70); "Black:" & "(" & strBlackId & ")" & _
' Black.Fname & " " & Black.Lname& _
' "(" & Black.Rating & ")" & "Games(" & Black.Games &
")" & _
' dblWhiteScore & " " & dblBlackScore

Current error is "Expected: End of statement
Previous error was: Expected Expression when the statement was as
follows:

prStr intNestLevel, "Game(" & strGameNumber & ")" & _
Tab(12) & "Match(" & strmatchNumber & ")"

I'm trying to find a way to print tab-delineated data to a file.

Thanks.
 
D

Douglas J. Steele

If you want a tab-delimited file, concatenate Chr(9) between your fields.
The Tab function is to create fixed-width output, not delimited output.

prStr intNestLevel, "Game(" & strGameNumber & ")" & _
Chr$(9) & "Match(" & strmatchNumber & ")" & Chr$(9) & _
"White:" & "(" & strWhiteId & ")" & _
White.Fname & " " & White.Lname & _
"(" & White.Rating & ")" & " Games(" & White.Games & ")" & _
Chr$(9) & "Black:" & "(" & strBlackId & ")" & _
Black.Fname & " " & Black.Lname& _
"(" & Black.Rating & ")" & "Games(" & Black.Games & ")" & _
dblWhiteScore & " " & dblBlackScore
 
C

Clif McIrvin

Hi Mike - Print knows what to do with ";", but I'd guess that's where
the complier is choking.

As to "tab delimited file", as I recall the Tab(nn) function simply
issued space characters until it reached the correct print column; which
means that it would work fine in a print (or even a write) statement,
but in a Let statement (which is what you're trying to pass to the sub)
I don't think it would have worked; even in GWBasic.

If you want a tab delimited file, issue a TAB character (chr(10), [or
chr$(10)] works) between your values.

Have you looked at the Access Report File | Export options? I just
exported one of my reports to a text file ... seems that would be orders
of magnitude easier than what you're attempting here.

You'd have to investigate the object model (methods), but if you can do
(it) from the UI menus, you can almost always do the same thing through
VBA.
 
M

MikeB

I guess I said it wrong. I want (and this is what Tab(n) seems to be
doing, to print columns of data to a file.

This is working exactly the way I want it to work.
Print #1, Time(), String(intNestLvl, "-") & _
"Game(" & strGameNumber & ")" _
; Tab(30); "Match(" & strmatchNumber & ")" _
; Tab(40); "White:" & "(" & strWhiteId & ")" & _
White.Fname & " " & White.Lname & _
"(" & White.Rating & ")" & " Games(" & White.Games &
")" _
; Tab(90); "Black:" & "(" & strBlackId & ")" & _
Black.Fname & " " & Black.Lname & _
"(" & Black.Rating & ")" & "Games(" & Black.Games &
")", _
dblWhiteScore, dblBlackScore

The problem seems to arise when I try and pass the output string ( a
combination of character strings and "Tab(n) functions(?) to a sub.

I guess what I"m really asking is how do I pass all that junk to a Sub
to print?

Of course, the below code has an error, but this is what I'm trying to
do...

Option Compare Database
Option Explicit

Sub prTest()
Open "Ratings_log.txt" For Append As #1
prStr Time(), String(5, "-") & _
"Game(" & "5" & ")" & _
Tab(30) & "Match(" & "7" & ")" _
; Tab(40); "White:" & "(" & "20" & ")" & _
"Jack" & " " & "Frost" & _
"(" & "900" & ")" & " Games(" & "8" & ")" _
; Tab(90); "Black:" & "(" & "17" & ")" & _
"Graham" & " " & "Crackers" & _
"(" & "975" & ")" & "Games(" & "17" & ")", _
"1", "0"
Close 1
Debug.Print "Done " & Now()
End Sub

Sub prStr(ByVal str As String)
Print #1, str
End Sub
 
M

MikeB

Hi Mike - Print knows what to do with ";", but I'd guess that's where
the complier is choking.

and that's what I'm trying to find a way to do. :)
As to "tab delimited file", as I recall the Tab(nn) function simply
issued space characters until it reached the correct print column; which
means that it would work fine in a print (or even a write) statement,
but in a Let statement (which is what you're trying to pass to the sub)
I don't think it would have worked; even in GWBasic.

Yes, I said it badly. What I want is a flat file with spaces so that
the data is printing in columns.
If you want a tab delimited file, issue a TAB character (chr(10), [or
chr$(10)] works) between your values.

I guess I'll try this next.
Have you looked at the Access Report File | Export options? I just
exported one of my reports to a text file ... seems that would be orders
of magnitude easier than what you're attempting here.

You'd have to investigate the object model (methods), but if you can do
(it) from the UI menus, you can almost always do the same thing through
VBA.

This, I don't even know where to start. I can't figure out how to
create a report of just lines of text.
 
T

Tom van Stiphout

On Fri, 26 Sep 2008 19:41:19 -0400, "Douglas J. Steele"

Rather than Chr$(9) I would recommend the equivalent but more readable
vbTab.

-Tom.
Microsoft Access MVP
 
C

Clif McIrvin

MikeB said:
Hi Mike - Print knows what to do with ";", but I'd guess that's where
the complier is choking.

and that's what I'm trying to find a way to do. :)
<snip>

If you want a tab delimited file, issue a TAB character (chr(10), [or
chr$(10)] works) between your values.

I guess I'll try this next.

oops ... I should have verified my memory before posting ... Doug is
correct, chr(9) is tab. (chr(10) is linefeed).
This, I don't even know where to start. I can't figure out how to
create a report of just lines of text.

Hmm. I just spent a few minutes looking for how to programmatically
export. I can open the export dialog, but I didn't find information on
how to actually do the export programmatically.

docmd.RunCommand(acCmdExport)

will open the export dialog, but that is just what you get from File |
Export.

To create an Access report that is simply lines of text, I did this:

1. Open a report in Preview
2. File | Export | Save as Type: Text Files | (Browse to desired
location) | Export
(Access creates "Access Report Name.txt" where "Access Report Name"
is the name of your
report.)

I've run out of time to do more digging -- maybe someone else in this
room can help you with automating exporting an Access report.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top