Solved

sql query please help..very urgent

Posted on 2006-06-27
2
268 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now