Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sql query please help..very urgent

Posted on 2006-06-27
2
Medium Priority
?
317 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 1200 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 800 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

610 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