4 Replies - 1846 Views - Last Post: 16 April 2013 - 09:45 PM Rate Topic: -----

#1 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

subscript out of range run time error '9' vb6 crystal report

Posted 16 April 2013 - 01:58 AM

I am getting this error when I try to pass an sql string to an external crystal report. extenal in the the report is not part of the project but a crystal report file. I have uploaded a summarised version of the project


Dim Report As New CrystalReport1

Set rs = New ADODB.Recordset
Dim strSql As String

Dim ReportStartDate As Date
Dim ReportEndDate As Date

ReportStartDate = txtStartDate.Text
ReportEndDate = txtEndDate.Text

strSql = "SELECT * from Outwards WHERE date >= #" & ReportStartDate & "#  And date <= #" & ReportEndDate & "# and ShiftNumber >= " & txtStartShift.Text & " And ShiftNumber <= " & txtEndShift.Text & ""
'rs.Open strSql, Con
rs.Open strSql, Con, adOpenKeyset, adLockOptimistic, adCmdText


Report.DiscardSavedData
Report.Database.Tables(1).SetDataSource rs, 3'>>> Where the error shows up

CRViewer1.ReportSource = Report.Application.OpenReport("C:\CrystalSample\NOPS36.rpt")

CRViewer1.Refresh
CRViewer1.ViewReport

Set Report = Nothing
Set rs = Nothing


Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: subscript out of range run time error '9' vb6 crystal report

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3448
  • View blog
  • Posts: 11,693
  • Joined: 12-December 12

Re: subscript out of range run time error '9' vb6 crystal report

Posted 16 April 2013 - 03:57 AM

I haven't looked in detail at your code but Date is a reserved word in most database systems so, if used as a field-name, needs to be enclosed in either square-brackets or back-ticks in the sql-statement. Much better would be to change the name of the field.

However, some systems allow the use of the word date, so this may not be the direct cause of your issue.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3448
  • View blog
  • Posts: 11,693
  • Joined: 12-December 12

Re: subscript out of range run time error '9' vb6 crystal report

Posted 16 April 2013 - 04:03 AM

"Subscript out of range"

Should it be Tables(0)? I don't use Crystal Reports, but worth asking.

This post has been edited by andrewsw: 16 April 2013 - 04:03 AM

Was This Post Helpful? 0
  • +
  • -

#4 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

Re: subscript out of range run time error '9' vb6 crystal report

Posted 16 April 2013 - 05:31 AM

I tried and its still giving me the same error
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: subscript out of range run time error '9' vb6 crystal report

Posted 16 April 2013 - 09:45 PM

Have a look at this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1