
VB 4.0, Crystal Reports and Access via ODBC
Quote:
> I am trying to invoke a Crystal Report from VB 4.0. The report
> reads data from an Access database using an ODBC driver. I have tried to
> do this in a number of different ways and I always get the same response,
> Error number 536 "Incorrect log on parameters".
> Does anyone out there know how to print a report under these
> circumstances? Alternatively is there anyway I could find out more about
> the "incorrect parameters"?
Hi James,
you don't state if you want to use the report control or the pe-engine.
Anyhow, here are both:
The CR control:
CrwReport.Connect = "DSN="
CrwReport.Connect = CrwReport.Connect & Trim$(Server) & ";"
CrwReport.Connect = CrwReport.Connect & "UID=" & Trim$(dbuserid) &
";"
CrwReport.Connect = CrwReport.Connect & "PWD=" & Trim$(dbpassword) &
";"
CrwReport.Connect = CrwReport.Connect & "DSQ=" & Trim$(dbname)
The PE-Engine:
Dim hJob As Integer
Dim rc As Integer
Dim DbLoginInfo As PELogOnInfo
' PEOpenEngine is done in form_load() or main sub.
hJob = PEOpenPrintJob(RepName)
rc = PEOutputToPrinter(hJob, 1)
DbLoginInfo.StructSize = PE_SIZEOF_LOGON_INFO
DbLoginInfo.ServerName = Server & Chr$(0)
DbLoginInfo.DatabaseName = dbname & Chr$(0)
DbLoginInfo.UserID = dbuserid & Chr$(0)
DbLoginInfo.PassWord = dbpassword & Chr$(0)
rc = PESetNthTableLogOnInfo(hJob, 0, DbLoginInfo, 1)
rc = PEStartPrintJob(hJob, True)
If (rc = 0) Then
' didn't succeed opening the window
rc = PEGetErrorCode(hJob)
If rc <> 0 Then
' If there is an error code, find out what it means
Dim Errortext As String
Dim TextHandle As Integer, TextLength As Integer, ErrNum As
Integer
ErrNum = PEGetErrorText(hJob, TextHandle, TextLength)
If rc = 0 Then
' If getting the text failed, say so
Errortext = "Error in ErrorTrap routine"
Else
' Get the text from the handle
Errortext = String$(TextLength, 0)
rc = PEGetHandleString(TextHandle, Errortext,
TextLength)
Errortext = Trim$(Errortext)
Errortext = Left$(Errortext, Len(Errortext) - 1)
End If
MsgBox "Error #" & ErrNum & vbCrLf & Errortext
End If
End If
DoEvents
While (PEGetWindowHandle(hJob) <> 0)
DoEvents
Wend
PEClosePrintJob hJob
' PECloseEngine is done in EndProgram()
--
Regards,
Product Developer
ATEX Media Solutions Development AS,
http://www.*-*-*.com/