Results 1 to 19 of 19

Thread: Query report CR11 and VB6 Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Unhappy Query report CR11 and VB6 Problem

    I am generating a report where it is showing all items which are in stock or out of stock

    Now I am taking that choice from a cmbstatus list.. so the value is 0 is in stock and 1 if out of stock

    now the sql query to run in the report is

    Code:
    select * from item where item.status = 1/0
    ( depending what the person chooses )

    how do i do this.. i did create a parameter field "stat" but i am unable to generate this formula.. I am passing the value via

    Code:
    crxReport.ParameterFields.GetItemByName("stat").AddCurrentValue st
    where st = the value chooses by user i.e. 0 or 1

    i gave in the selection formula

    Code:
    {item.status} = {?stat}
    But it gives error

    Code:
    A Number is required here
    what to do ????

    once this problem is solved i have another multitable query problem which i will give later

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Query report CR11 and VB6 Problem

    Why not just pass a SQL String to the report instead:

    VB Code:
    1. Private Sub Form_Load()
    2. Dim rs As ADODB.Recordset
    3. Dim strSQL As String
    4.  
    5.     strSQL = "select * from item where item.status = '" & cmbstatus & "';"
    6.     rs.Open strSQL, conn, . . .
    7.            
    8.             With Report
    9.                 .Database.SetDataSource rs
    10.                 .DiscardSavedData
    11.             End With
    12.    
    13. Set Report = Nothing
    14.  
    15. rs.Close
    16. Set rs = Nothing
    17.  
    18. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    can u elaborate

    it gives datatype conversion error on line

    rs.Open strSQL, conn, . . .

  4. #4
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Query report CR11 and VB6 Problem

    Change the data type of your parameter field.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    its string

    and i dont think i m passing a parameter to it.. as its not mentioned on code

  6. #6
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Query report CR11 and VB6 Problem

    Is item.status a number? if so you need to make sure you are comparing it to a number and not a string.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    both are integer

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    this is the code

    VB Code:
    1. If reportname = "items" Then
    2.     reportname = App.Path & "\reports\items.rpt"
    3.     Set crxReport = crxApp.OpenReport(reportname)
    4.     Dim strSQL As String
    5.     strSQL = "select * from item_details where item_details.status = '" & opt & "';"
    6.     rs.OpenRecordset strSQL
    7.    
    8.     With crreport
    9.                 .Database.SetDataSource rs
    10.                 .DiscardSavedData
    11.             End With

  9. #9
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Query report CR11 and VB6 Problem

    I was originally refering to your first post. What is the error with that code?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    oh yeah .. fixed.. 1 was string and 1 was number.. now working..

    Now another 2 queries

    1) When the parameter value of "stat" is 0 .. i want to show a text like "shipped" somewhere.. how do i do this connection in the report ??

    2) There is another 2 queries.. if the parameter value is 0 then the following query should be run

    Code:
    select order_details.order_id FROM order_details INNER JOIN shipping ON order_details.order_id = shipping.order_id
    else the following should be run ( if parameter "stat" = 1 )

    Code:
    SELECT order_details.order_id FROM order_details WHERE order_details.order_id NOT IN (SELECT shipping.order_id FROM shipping )
    how do i do this codeing in the report in to run seperate queries depending upon the parameter value??

    thanks

  11. #11
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Query report CR11 and VB6 Problem

    If you are passing stat to the report you can make a formula field to display different things depending on the parameter.

    Just make a new formula and add a if statement to it.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    i tired and i put this in selection formula editor

    Code:
    if {?option} = 0 then select order_details.order_id FROM order_details INNER JOIN shipping ON order_details.order_id = shipping.order_id
    gives error

    a number, currency amount, boolean,date,time or string is expected here

    on the line select order_details.order_id

    what to do ??

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    please shed some light here..

    help on the above post..

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    also one more problem

    I increased the width of the details field in report.. and generated one so that result goes in 2-3 pages.. but it just shows 1st page.. whats wrong??

  15. #15
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Query report CR11 and VB6 Problem

    Quote Originally Posted by khandu
    oh yeah .. fixed.. 1 was string and 1 was number.. now working..

    Now another 2 queries

    1) When the parameter value of "stat" is 0 .. i want to show a text like "shipped" somewhere.. how do i do this connection in the report ??

    2) There is another 2 queries.. if the parameter value is 0 then the following query should be run

    Code:
    select order_details.order_id FROM order_details INNER JOIN shipping ON order_details.order_id = shipping.order_id
    else the following should be run ( if parameter "stat" = 1 )

    Code:
    SELECT order_details.order_id FROM order_details WHERE order_details.order_id NOT IN (SELECT shipping.order_id FROM shipping )
    how do i do this codeing in the report in to run seperate queries depending upon the parameter value??

    thanks
    To answer #1 all you have to do is make a formula field with an if statement in it.

    If {?Parameter} = 0 Then
    "Shipped"
    else
    "Not Shipped

    then place the formula field on the report somewhere.

    not sure how to answer #2

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    thanks..

    1) resolved ... i was tryin to pass a value to a txtbox.. heh.. so simple ur method

    some1 please help in 2nd and 3rd problem

    2) as mentioned above : multitable query run depending upon the parameter value

    3) I increased the width of the details field in report.. and generated one so that result goes in 2-3 pages.. but it just shows 1st page.. whats wrong??

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    *bump*

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    Hey some1 suggested

    VB Code:
    1. dim strTheQuery
    2. If stat = 0 Then
    3.     strTheQuery = select order_details.order_id FROM order_details INNER JOIN shipping ON order_details.order_id = shipping.order_id
    4. Else
    5.     strTheQuery = SELECT order_details.order_id FROM order_details WHERE order_details.order_id NOT IN (SELECT shipping.order_id FROM shipping )
    6. End If

    So what to do with strthequery and how to pass it?? as a parameter???? or what

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Query report CR11 and VB6 Problem

    bump..

    some1 please help with the problem No 2) and 3) which is mentioned 2 posts above..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width