Reports From VB

barrios1

New member
Local time
Today, 22:04
Joined
Jan 21, 2003
Messages
7
HI again

This question relates to a thread satrted br FiRe5torm on 20/07/03. The code for opening an Access report from vb goes:

On Error GoTo HandleErrors

'points to the location of the database to open
Dim dbName As String
'name of the report to print
Dim rptName As String
'print type
Dim Preview As Long
'used to story current main recordset
Dim strFilter As String

'doesnt seem needed
'Const acNormal = 0
'Const acPreview = 2

Dim appAccess As Access.Application
Set appAccess = New Access.Application


dbName = App.Path & "\nhsdirectory.mdb"
rptName = "AllStaffRecs"
Preview = acPreview 'acNormal


With appAccess
'.OpenCurrentDatabase (App.Path & "\nhsdirectory.mdb")
.OpenCurrentDatabase filepath:=dbName
'if user wants to preview print first then show print preview screen
If Preview = acPreview Then
'alow the user to see the report
.Visible = True
'open report in preview mode
.DoCmd.OpenReport rptName, acViewPreview
Else
'open the report
.DoCmd.OpenReport rptName

End If
End With

ExitHere:
Exit Sub

HandleErrors:
Select Case Err.Number
Case 2501
MsgBox "No rows have been selected to print", vbOKOnly, "Print Error"
Case Else
MsgBox Err.Description, vbOKOnly, "Print Error"
End Select
Resume ExitHere

End Sub


My problem is that I would like the user to be able to have a good look at the report on screen before deciding to print. With the above code, the report appears for a second and disappears when the 'End Sub' line is reached (I assume).

Anyone have ideas around this?

Go raibh maith agaibh!!

Jeno
 
Thanks for the reply

No I did not alter this in any way. If I substitute scNormal for the acPreview the document prints fine!!
 

Users who are viewing this thread

Back
Top Bottom