Hi,
Using data reports in VB6 is a headache espically when it is a little more complex than the case we have here. Most of the time reports contains parent data in the header in addition to child sub form or grid. Personally I had a lot of problems trying to do it through VB6 data enviroment report so I came to a trick to use internet explorer or Excel as my printing utilities where I have prepared a template for excel in which I export my data to print it and close the object all in the background. Same for internet explorer but it doesn't need a template. It is very fast and reliable (faster and more reliable than crystal reports) but of course you will need to use some excel VBA and HTML. I have enclosed below the last examples I used this code in.
HTML
Private Sub cmdExport_Click()
Dim A As Integer
Dim s As Integer
On Error GoTo E
If Me.txtField(0) = "" Or Me.txtField(7) = "" Or Not Me.MSHFlexGrid1.Rows > 0 Then
MsgBox "There is no result to Export", , "Export Failure"
Else
Dim str As String
str = "<html><head></head><body><h1><b>Specialized Medical Center Hospital</b></h><h3><b>Tel. 4164000 Fax 4648493</b></h><br><br><br>" & _
"<table><tr><td><b>Patient ID</b></td><td>" & _
Me.txtField(7) & _
"</td><td> </td><td><b>Register Date</b></td><td>" & _
Me.txtField(1) & _
"</td></tr><tr><td><b>Patient Name</b></td><td>" & _
Me.txtField(5) & _
"</td><td> </td><td><b>Register Time</b></td><td>" & _
Me.txtField(2) & _
"</td></tr><tr><td><b>Date of Birth</b></td><td>" & _
Me.txtField(4) & _
"</td><td> </td><td><b>Priority</b></td><td>" & _
Me.txtField(3) & _
"</td></tr><tr><td><b>Gender</b></td><td>" & _
Me.txtField(8) & _
"</td><td> </td><td><b>Doctor</b></td><td>" & _
Me.txtField(9) & _
"</td></tr><tr><td><b>Sample ID</b></td><td>" & _
Me.txtField(0) & _
"</td><td> </td><td><b>Specimen</b></td><td>" & _
Me.txtField(6) & _
"</td></tr></table><br><table border=1 width=650><tr height=33><td><b>Test Name</b></td><td><b>Result</b></td><td><b>Unit</b></td><td colspan=2><b>Reference Range</b></td><td><b>Result Date</b></td><td><b>Verified</b></td></tr>"
For A = 0 To Me.MSHFlexGrid1.Rows - 1
If ttype <> "limited" Or Me.MSHFlexGrid1.TextMatrix(A, 7) = "Verified" Then
str = str & "<tr height=42><td>" & Me.MSHFlexGrid1.TextMatrix(A, 1) & _
"</td><td>" & IIf(Me.MSHFlexGrid1.TextMatrix(A, 2) = "", " ", Me.MSHFlexGrid1.TextMatrix(A, 2)) & _
"</td><td>" & Me.MSHFlexGrid1.TextMatrix(A, 3) & _
"</td><td align=center>" & IIf(Me.MSHFlexGrid1.TextMatrix(A, 5) = "", " ", Me.MSHFlexGrid1.TextMatrix(A, 5)) & _
"</td><td>" & IIf(Me.MSHFlexGrid1.TextMatrix(A, 4) = "", " ", Me.MSHFlexGrid1.TextMatrix(A, 4)) & _
"</td><td>" & IIf(Me.MSHFlexGrid1.TextMatrix(A, 6) = "", " ", Me.MSHFlexGrid1.TextMatrix(A, 6)) & _
"</td><td>" & Me.MSHFlexGrid1.TextMatrix(A, 7) & "</td></tr>"
End If
Next
str = str & "</table><br><br><h6 align=right>Exported On " & Now() & " by " & title & " " & fullname & "</h></p></body></html>"
Dim Y As String
Y = InputBox("What do you want to name your file", "File Naming", "MRN")
Y = IIf(IsNull(Y), "MRN", Y)
WriteTextFile "c:\" & Y & ".html", str
MsgBox "Your file was saved as C:\" & Y & ".html", , "Save Confirmation"
End If
E1:
Exit Sub
E:
MsgBox "There was an error exporting the data", , "Export Failure"
On Error GoTo E1
End Sub
EXCEL
Private Sub cmdPrint_Click()
On Error GoTo E
If Me.txtField(0) = "" Or Me.txtField(7) = "" Or Not Me.MSHFlexGrid1.Rows > 0 Then
MsgBox "There is no result to print", , "Print Failure"
Else
Dim xl
Dim xlsheet
Dim xlwbook
Set xl = CreateObject("Excel.Application")
Dim A As Integer
Dim s As Integer
Set xlwbook = xl.Workbooks.Open("C:\Lab\report1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)
With xlsheet
.range("B10") = Me.txtField(0)
.range("B11") = Me.txtField(7)
.range("B12") = Me.txtField(5)
.range("B13") = Me.txtField(4)
.range("B14") = Me.txtField(8)
.range("F10") = Me.txtField(1)
.range("F11") = Me.txtField(2)
.range("F12") = Me.txtField(3)
.range("F13") = Me.txtField(9)
.range("F14") = Me.txtField(6)
End With
x = 19
For A = 0 To Me.MSHFlexGrid1.Rows - 1
With xlsheet
If ttype <> "limited" Or Me.MSHFlexGrid1.TextMatrix(A, 7) = "Verified" Then
.range("A" & x) = Me.MSHFlexGrid1.TextMatrix(A, 1)
.range("B" & x) = Me.MSHFlexGrid1.TextMatrix(A, 2)
.range("C" & x) = Me.MSHFlexGrid1.TextMatrix(A, 3)
.range("D" & x) = Me.MSHFlexGrid1.TextMatrix(A, 5)
.range("E" & x) = Me.MSHFlexGrid1.TextMatrix(A, 4)
.range("F" & x) = Me.MSHFlexGrid1.TextMatrix(A, 6)
.range("G" & x) = Me.MSHFlexGrid1.TextMatrix(A, 7)
x = x + 1
End If
End With
Next
xlsheet.PrintOut
xl.ActiveWorkbook.Close False, "C:\Lab\report1.xls"
xl.Quit
xl.Quit
Set xl = Nothing
Set xlwbook = Nothing
End If
E1:
Exit Sub
E:
xl.ActiveWorkbook.Close False, "C:\Lab\report1.xls"
xl.Quit
xl.Quit
Set xl = Nothing
Set xlwbook = Nothing
MsgBox "There was an error printing your report please contact your IT representative", , "Print Failure"
On Error GoTo E1
End Sub
It is never about the number of languages you know, you either have the logic of programming or you don't.