Solved

sql query please help..very urgent

Posted on 2006-06-27
2
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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