Avatar of Whing Dela Cruz
Whing Dela Cruz
Flag for Anguilla asked on

Crystal Report

How could I set the database manually in my code below?
I am using mssql7 and my database is "CASHIERFILE" and
I am using seagate 8.5 as crystal report

Public Sub OroExpenses()
Dim Report As CRAXDRT.Report
Dim str As String
    Set Report = New crysExpenses
    str = "{TblPora.Thedate} =#" & Format$(mainfrm.Mydate) & "# And {TblPora.Typep}='" & RP & "'"
    Report.RecordSelectionFormula = str
    Report.ReadRecords
    Call Report.SelectPrinter(Report.DriverName, Report.PrinterName, Report.PortName)
    Report.H1.SetText Header
    cr.ReportSource = Report
    cr.ViewReport
    cr.EnableExportButton = True
    cr.EnablePopupMenu = True
    cr.Zoom 94
    Set Report = Nothing
End Sub

Open in new window

Visual Basic ClassicCrystal Reports

Avatar of undefined
Last Comment
Whing Dela Cruz

8/22/2022 - Mon
SOLUTION
Mike McCracken

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Haroon Ur Rashid

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Whing Dela Cruz

ASKER

Hi Haroon!
Sorry but can you correct my code below base of the code you had shared to me..
My Database is DB001 I'm using mssql7
My dbuser is OroSales
      pwd = sa
I've got an error when I execute the code..
Thanks!
Public Sub Oro_Sold()
Call ConnectReportToDatabase(cr)
Dim str As String
 
            Set Report = New crysSOLDPRODUCT
            str = "{SOLDITEM.THEDATE} = #" & mainfrm.Mydate & "#"
            Report.RecordSelectionFormula = str
            Report.ReadRecords
            Call Report.SelectPrinter(Report.DriverName, Report.PrinterName, Report.PortName)
            Report.H1.SetText Header(0)
            Report.H2.SetText Header(1)
            Report.H3.SetText Header(2)
            cr.ReportSource = Report
            cr.ViewReport
            cr.Zoom 94
            Set Report = Nothing
End Sub
 
Public Sub ConnectReportToDatabase(cr As CrystalReport)
'cr.LogonInfo(0) = "DSN =WapdaCSS; UID =" & DBUser & " ; PWD =" & DBPassword & " "
cr.Connect = "DSN =" & SystemDSN & "; UID =" & DBUser & " ; PWD =" & DBUserPwd & " "
End Sub

Open in new window

Brook Braswell

Here is a function I use, passing the report byRef to connect it to a database

Public Sub SetReportDatabase(ByRef RPT As CRAXDRT.Report)
           Dim iErr As Integer
           Dim t As Integer
           Dim srT As Integer
10         iErr = 0
20         On Error GoTo PROC_ERR
30         For t = 1 To RPT.Database.Tables.count
'             RPT.Database.Tables(t).ConnectBufferString = "DSN=" & gDBNAME & ";;UseDSNProperties=0"
              ' YOUR CONNECTION FROM ABOVE
              RPT.Database.Tables(t).ConnectBufferString =  "DSN =" & SystemDSN & "; UID =" & DBUser & " ; PWD =" & DBUserPwd & " "
50         Next
           SetSubReportDatabase RPT
PROC_EXIT:
60         Exit Sub
PROC_ERR:
70         If InStr(1, UCase(ERR.Description), "READ-ONLY", vbTextCompare) > 0 Then Exit Sub
80         If iErr > 3 Then
90            ' YOUR ERROR TRAP HERE
100           Resume PROC_EXIT
110        Else
120           iErr = iErr + 1
130           Resume
140        End If
           
End Sub

Open in new window

Whing Dela Cruz

ASKER
Hi! Brook1966,
I've got an error that say's "Can't assign to read only property"

ConnectBufferString

I'm not sure my code below is correct! Can you tell what part of that code is wrong?
Thanks!

Public Sub IliganExpenses()
Call SetReportDatabase(Report)
 
Dim str As String
    Set Report = New crysExpensesIligan
    str = "{TblPora.Thedate} =#" & Format$(mainfrm.Mydate) & "# And {TblPora.Typep}='" & RP & "'"
    Report.RecordSelectionFormula = str
    Report.ReadRecords
    Call Report.SelectPrinter(Report.DriverName, Report.PrinterName, Report.PortName)
    Report.H1.SetText Header(0)
    Report.H2.SetText Header(1)
    Report.H3.SetText "Date: " & Format$(mainfrm.Mydate.Value, "MMMM DD YYYY")
    Report.H4.SetText Header(2)
    cr.ReportSource = Report
    cr.ViewReport
    cr.EnableExportButton = True
    cr.EnablePopupMenu = True
    cr.Zoom 94
    Set Report = Nothing
End Sub
Public Sub SetReportDatabase(ByRef RPT As CRAXDRT.Report)
           Dim iErr As Integer
           Dim t As Integer
           Dim srT As Integer
10         iErr = 0
20         On Error GoTo PROC_ERR
30         For t = 1 To RPT.Database.Tables.Count
             'RPT.Database.Tables(t).ConnectBufferString = "DSN=" & gDBNAME & ";;UseDSNProperties=0"
              ' YOUR CONNECTION FROM ABOVE
              RPT.Database.Tables(t).ConnectBufferString = "DSN =" & "Sample" & "; UID =" & "Winpos" & " ; PWD =" & "sa" & " "
50         Next
           SetSubReportDatabase RPT
PROC_EXIT:
60         Exit Sub
PROC_ERR:
70         If InStr(1, UCase(Err.Description), "READ-ONLY", vbTextCompare) > 0 Then Exit Sub
80         If iErr > 3 Then
90            ' YOUR ERROR TRAP HERE
100           Resume PROC_EXIT
110        Else
120           iErr = iErr + 1
130           Resume
140        End If
           
End Sub

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Brook Braswell

on what line of what module are you getting your error?
I had left the READ ONLY in the error trap to ignore such errors...
Whing Dela Cruz

ASKER
RPT.Database.Tables(t).ConnectBufferString =  "DSN =" & SystemDSN & "; UID =" & DBUser & " ; PWD =" & DBUserPwd & " "
That line sir.. The ConnectBufferString
Brook Braswell

change line 70 based on the error you received..

70         If InStr(1, UCase(Err.Description), "READ-ONLY", vbTextCompare) > 0 Then Exit Sub

to
70         If InStr(1, UCase(Err.Description), "READ ONLY", vbTextCompare) > 0 Then Exit Sub

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Brook Braswell

Your report objects
crysSOLDPRODUCT, crysExpensesIligan

Are these DSRs?



SOLUTION
Brook Braswell

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Whing Dela Cruz

ASKER

ICRDesigner Sir...
Still have the same error rigth now sir...
Brook Braswell

Remove the SetReportDatabase...

Try the ADO version instead.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Whing Dela Cruz

ASKER
I'll try it now.. Thanks!
Whing Dela Cruz

ASKER
Thank you so much..