Results 1 to 3 of 3

Thread: Running Access reports in VB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123

    Post

    I often use the following code to successfully run Access queries in VB:

    strParam = "PARAMETERS [paramName] TEXT; "
    strSQL = dbData.QueryDefs("queryName").SQL
    Set qdf = dbData.CreateQueryDef("", strParam & strSQL)
    qdf("paramName") = textfield
    Set rs = qdf.OpenRecordset(dbOpenSnapshot)

    Does anybody know of anything similar to run an Access report, based on a query that takes a parameter.

    Note that I am trying to avoid the situation where I have to open the Access application. I don't want to have to do:

    Set acc = New Access.Application
    acc.DoCmd.OpenReport rptName, acViewNormal

    because this gives me other problems.

    I am using VB6, Access 97, Jet/DAO.

    Thanks in advance.


    [This message has been edited by Michael (edited 06-24-1999).]

  2. #2
    Lively Member
    Join Date
    Jun 1999
    Location
    Raleigh, NC
    Posts
    70

    Post

    I'm not sure you can run an Access report from VB without instantiating Access. If you want to make data available for an Access report, why not create a temporary table for the report to use, then populate it with the results of an Append query that takes the parameter. If you know the query ahead of time, you could actually save it to the .mdb file and pass in the parameter.

    set qdf = db.querydefs("query name")
    qdf!parameter_name = "parameter value"
    qdf.Execute

    and the query sql would be something like
    INSERT INTO tblReport (field1, field2, field3) SELECT fieldthis, fieldthat, fieldother FROM tbl1 WHERE filedother = [param]

    Does this help?
    bash

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123

    Post

    Hi bash

    Thanks for your suggestion. It may work. I know the query in advance, and the value of the parameter is determined at run time.

    The only reservation I have is that I am running on a multi-user system and if I use a fixed name for the temp table then I risk overwriting it. If I use a unique table name then I have the problem of telling my report which table to use.

    Why is life never simple?

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