CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Parameter Query

  1. #1
    Join Date
    Aug 1999
    Location
    Blue Springs, MO
    Posts
    43

    Parameter Query

    I have a report in Access that I need to run from VB6.

    The report is based on a query.

    The query is a parameter query that needs a CustID.

    I need to pass that CustID in from the VB program.

    How can I give the query the CustID so the report will print properly?

    Thanks!


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Parameter Query

    You can either send the parameter, or I found it is easier to delete the query and enter the new one with the parameter

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Aug 1999
    Location
    Blue Springs, MO
    Posts
    43

    Re: Parameter Query

    That would be fine, but I don't know how to do either...

    Can you shed some light on that?

    Thanks!


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Parameter Query

    'delete stored proc (query)
    sSQL = "DROP PROCEDURE qryRHDByMonth"
    cn.Execute sSQL


    'create query
    sSQL = "CREATE PROCEDURE qryRHDByMonth as SELECT * from Table where ...."'your param is here

    cn.Execute sSQL

    where cn is connection object

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Aug 1999
    Location
    Blue Springs, MO
    Posts
    43

    Re: Parameter Query

    I get an error when I try to execute....

    SYNTAX ERROR IN DROP TABLE OR DROP INDEX...

    Ugh....


  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Parameter Query

    On my computer it runs fine. I am using Access97. Check help for using SQL statement DROP

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  7. #7
    Join Date
    Aug 1999
    Location
    Blue Springs, MO
    Posts
    43

    Re: Parameter Query

    Would you mind providing your full code that shows the connection information, also?

    I think that may be the difference...

    Thanks!


  8. #8
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Parameter Query

    Dim sConn As String

    sConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & DBPATH & ";uid=;pwd=;"
    Set cn = New ADODB.Connection
    cn.CursorLocation = adUseClient
    cn.ConnectionString = sConn
    cn.Open sConn


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  9. #9
    Join Date
    Aug 1999
    Location
    Blue Springs, MO
    Posts
    43

    Re: Parameter Query

    I'm still getting the error...

    I start a new project,add a reference to "Microsoft ActiveX Data Objects 2.5 Library"

    Add a command button to a form. Add this code to the button:
    Dim sConn as string
    Dim DBPATH as string
    DBPATH = App.Path & "\test.mdb"

    sConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & DBPATH & ";uid=;pwd=;"
    set cn = new ADODB.Connection
    cn.CursorLocation = adUseClient
    cn.ConnectionString = sConn
    cn.Open sConn

    'delete stored proc (query)
    sSQL = "DROP PROCEDURE qrytest"
    cn.Execute sSQL


    'create query
    sSQL = "CREATE PROCEDURE qrytest as SELECT * from tbltest" 'your param is here

    cn.Execute sSQL



    Running the program, and clicking the button still gives me the error give 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

Featured