bowen18
asked on
Add text file to Data Report
Using Data Report Designer to create reports from an Access 97 database. However I have some information stored in a text file that I would like to display in the Data Report. How can I have the Data Report display the text file?
Thanks in advance for any and all help.
-Jeff
Thanks in advance for any and all help.
-Jeff
ASKER
Thanks for the quick response. This is what I've been using on my forms to display the text file. Are you saying this will work in some form on the Data Report?
Dim MyData As String
Open "H:\time\data\" & deTime.rscomTime![Name] & ".txt" For Input As #1
Do Until EOF(1)
Input #1, MyData
txtComments.Text = txtComments.Text & vbCrLf & MyData
Loop
Close #1
Dim MyData As String
Open "H:\time\data\" & deTime.rscomTime![Name] & ".txt" For Input As #1
Do Until EOF(1)
Input #1, MyData
txtComments.Text = txtComments.Text & vbCrLf & MyData
Loop
Close #1
Yes, that will work, as long as you substitute properly for the clunky way you have to reference controls on the report.
You could probably avoid some screen flicker and refresh time, by the way, by just using some buffer variable and making a single assignment to the textbox.
i.e.,
sBuffer = ""
Do Until EOF(1)
Input #1, MyData
sBuffer = sBuffer & MyData
Loop
Close #1
txtComments.Text = sBuffer
You could probably avoid some screen flicker and refresh time, by the way, by just using some buffer variable and making a single assignment to the textbox.
i.e.,
sBuffer = ""
Do Until EOF(1)
Input #1, MyData
sBuffer = sBuffer & MyData
Loop
Close #1
txtComments.Text = sBuffer
ASKER
I apologize, but I'm not sure I understand. At what point/procedure would I add my text file? If its not too much trouble, could you possibly provide an example?
Thanks!
-Jeff
Thanks!
-Jeff
ASKER
Also, its giving me a varible not defined error on the txtComments.text part. I double checked and txtComments is the correct name of the text box on the report. Any ideas?
Thanks,
-Jeff
Thanks,
-Jeff
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK - OOPS!
please get rid of the reference to #1 that I left in the code in that last post and substitute #nHandle. Sorry about that... I hit submit too fast.
The offending line should read:
Input #nHandle, MyData
Sorry.
please get rid of the reference to #1 that I left in the code in that last post and substitute #nHandle. Sorry about that... I hit submit too fast.
The offending line should read:
Input #nHandle, MyData
Sorry.
ASKER
Wow, that's alot of great information. Your going above and beyond what I expected! I do have one issue with the supplied code. When I run the first part to get the index, it gives me a varible not defined error on rptStatement.Sections. Any help is very much appreciated.
Thanks,
-Jeff
Thanks,
-Jeff
Please type that line of code that give the error.
ASKER
> For Each mySect In rptStatement.Sections
the debugger highlights rptStatement.Sections as the culprit.
the debugger highlights rptStatement.Sections as the culprit.
Just replace rptStatement with the name of YOUR report object.
ASKER
Thanks for all your help but I'm still having a problem. Now its with the last line of the code.
You wrote
PageHeader.Controls(IndexF orTxtComme ntsGoesHer e).Caption = sBuffer
I changed it to
Section1.Controls(21).Capt ion = sBuffer
because Section1 is the Details section which is where txtComments is. And 21 is the index of the txtComments text box.
The error I'm getting is a "varible not defined" and its looking at Section1 of the Section1.Controls(21).Capt ion = sBuffer line. I've used Details.Controls(21).capti on and even drUserInfo.Sections(1).Con trols(21). Caption with no luck.
Probably another one of my stupid mistakes but would love some help :)
Thanks,
Jeff
You wrote
PageHeader.Controls(IndexF
I changed it to
Section1.Controls(21).Capt
because Section1 is the Details section which is where txtComments is. And 21 is the index of the txtComments text box.
The error I'm getting is a "varible not defined" and its looking at Section1 of the Section1.Controls(21).Capt
Probably another one of my stupid mistakes but would love some help :)
Thanks,
Jeff
in my code i'm expecting you have the text you want on the report in a variable called sBuffer. Is it there?
I actually used rptLabel controls in my app and they certainly had a .Caption property. Perhaps the text box you are using doesn't. Perhaps it has a .Text property like standard textboxes.
So you can try two things.
(1) Change the code to
Section1.Controls(21).Text = sBuffer
If that fails,
(2) change it back to .Caption, set a breakpoint (hit F9 while you edit the line in the code window), and let the project run.
It will stop at the breakpoint and you can let your mouse hover over the sBuffer part of the code. The contents of sBuffer will become visible. Are the contents there???
Obviously you can do these in reverse order if you want.
I actually used rptLabel controls in my app and they certainly had a .Caption property. Perhaps the text box you are using doesn't. Perhaps it has a .Text property like standard textboxes.
So you can try two things.
(1) Change the code to
Section1.Controls(21).Text
If that fails,
(2) change it back to .Caption, set a breakpoint (hit F9 while you edit the line in the code window), and let the project run.
It will stop at the breakpoint and you can let your mouse hover over the sBuffer part of the code. The contents of sBuffer will become visible. Are the contents there???
Obviously you can do these in reverse order if you want.
ASKER
I had to modify the code you sent me eariler to grab the section name. Its as follows:
Dim curSect As Object
For Each curSect In drUserInfo.Sections
If curSect.Name = "Section1" Then
curSect.Controls(21).Capti on = sBuffer
End If
Next
Good news is its working this way. I can't thank you enough for all your help! If I had a million points, I'd give them to you.
-Jeff
Dim curSect As Object
For Each curSect In drUserInfo.Sections
If curSect.Name = "Section1" Then
curSect.Controls(21).Capti
End If
Next
Good news is its working this way. I can't thank you enough for all your help! If I had a million points, I'd give them to you.
-Jeff
You're very welcome.
Does it make you wonder if more powerful reporting tools might be useful??? <grin>
FYI, I am a REAL fan of VS View Reporting Edition from ComponentOne. Among MANY other features, the two I most appreciate are: it allows me to build a report definition in Access, import to this tool and use it in VB to produce a report with three lines of code AND it supports writing PDF files as output (as well as MANY export formats).
Very cool and worth the money. But for real value, you probably shouldn't buy just THAT tool. Their whole suite of tools (Call ComponentOne Studio for ActiveX - or .NET - pick one) is just a little more than the price of the single tool and you get so many other fine controls (including two of the most popular grids in the VB world: TrueDBGrid and VSFlexGrid).
Just one developer's opinion.
Does it make you wonder if more powerful reporting tools might be useful??? <grin>
FYI, I am a REAL fan of VS View Reporting Edition from ComponentOne. Among MANY other features, the two I most appreciate are: it allows me to build a report definition in Access, import to this tool and use it in VB to produce a report with three lines of code AND it supports writing PDF files as output (as well as MANY export formats).
Very cool and worth the money. But for real value, you probably shouldn't buy just THAT tool. Their whole suite of tools (Call ComponentOne Studio for ActiveX - or .NET - pick one) is just a little more than the price of the single tool and you get so many other fine controls (including two of the most popular grids in the VB world: TrueDBGrid and VSFlexGrid).
Just one developer's opinion.
The pain about this is that you can't simply assign to it. You have to know the index of the control to do that.
So force your app to tell you the index of the control you want. I always paste this function into my reports for this purpose:
Private Sub WriteOutIndex()
Dim iCtrl As Integer
Dim mySect As Object
For Each mySect In rptStatement.Sections
Debug.Print " --> " & mySect.Name
For iCtrl = 1 To mySect.Controls.Count
Debug.Print " " & mySect.Controls(iCtrl).Nam
Next
Next
Set mySect = Nothing
End Sub
I call it in the report's intialize event and comment it out after I have the values I need from it during my report design. If I need to add any controls, I just uncomment it and let it run again.
Once you have the index number, you can use code like this to set the caption of your control:
MySectionName.Controls(Ind
where sBuffer is the string you have populated by reading your text file.
Do you need code for reading the file?