Solved

sql query please help..very urgent

Posted on 2006-06-27
2
276 Views
Last Modified: 2013-12-25
My program will call  a crystal report template if my sql query count * > 0 but even if my count * is 0, still program going into the    If loop-- and calling crysal template which is not supposed to do  so..

Pls help..

Dim rsUpdateROHS As ADODB.Recordset
     Call ReadDBSetting
     Set CONNOW = New ADODB.Connection
     CONNOW.Open gstrContStr
     Set rsUpdateROHS = New ADODB.Recordset
     
     strSQL = "select  count(*) from approvedcountries where countries in (select ShipTo from LoadPlan WHERE   DJFile_Name ='" & Trim(txtDJFile) & "')"

     rsUpdateROHS.Open strSQL, CONNOW, adOpenStatic, adLockOptimistic

     If Not rsUpdateROHS.EOF Then                    ''Eventhough my select count * is 0 still program going to crytal template

      CRAck.Reset
      CRAck.ReportFileName = App.Path & "\Report\ROHS1.rpt"
      CRAck.Connect = CONNOW
      CRAck.Destination = crptToWindow
      'CRAck.WindowState = crptMaximized
      CRAck.Action = 1

      rsUpdateROHS.Close
      Set rsUpdateROHS = Nothing
     
      Else        ----------Should go else or end sub of count * is 0
      End Sub
     
0
Comment
Question by:nyee84
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 16998540
 '>change the sql to give the count(*) a name:

  strSQL = "select  count(*) counter from approvedcountries where countries in (select ShipTo from LoadPlan WHERE   DJFile_Name ='" & Trim(txtDJFile) & "')"

     rsUpdateROHS.Open strSQL, CONNOW, adOpenStatic, adLockOptimistic

     If rsUpdateROHS.fields("counter").value > 0 Then                    '< change here to use that field value.

      CRAck.Reset
      CRAck.ReportFileName = App.Path & "\Report\ROHS1.rpt"
      CRAck.Connect = CONNOW
      CRAck.Destination = crptToWindow
      'CRAck.WindowState = crptMaximized
      CRAck.Action = 1

      rsUpdateROHS.Close
      Set rsUpdateROHS = Nothing
     
      Else        ----------Should go else or end sub of count * is 0
      End Sub


select count(*) will return ALWAYS 1 line. always except when the statement fails (which would go to the error handling)
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 200 total points
ID: 16998984
add a having clause to not generate a row when the reult is zero...
but basically you should probably just check that the value returned isn't zero and bypass the report generation that way...

 strSQL = "select  count(*) from approvedcountries where countries in (select ShipTo from LoadPlan WHERE   DJFile_Name ='" & Trim(txtDJFile) & "') having count(*) <> 0 "
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question