Query into VBA

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mat

    #1

    Query into VBA

    Hello

    I need to be able to access a query in VBA so I can cycle through it
    and write parts of it out to a text file.

    I have managed this with a database so far, but have now got a bit
    stuck.

    My database bit goes like this


    *************** *************** *************** *******
    Dim RST As Recordset
    Dim QryRST As Recordset


    Set DBS = CurrentDb()
    Set RST = DBS.OpenRecords et("SchoolDB", dbOpenTable)


    With RST
    While not .EOF
    'Do export routine in here.
    .MoveNext
    Wend
    End With
    *************** *************** *************** *********

    I basically want the same sort of thing except from a table.


    Thanks for any help


    Mat

  • salad

    #2
    Re: Query into VBA

    Mat wrote:
    [color=blue]
    > Hello
    >
    > I need to be able to access a query in VBA so I can cycle through it
    > and write parts of it out to a text file.
    >
    > I have managed this with a database so far, but have now got a bit
    > stuck.
    >
    > My database bit goes like this
    >
    >
    > *************** *************** *************** *******
    > Dim RST As Recordset
    > Dim QryRST As Recordset
    >
    >
    > Set DBS = CurrentDb()
    > Set RST = DBS.OpenRecords et("SchoolDB", dbOpenTable)
    >
    >
    > With RST
    > While not .EOF
    > 'Do export routine in here.
    > .MoveNext
    > Wend
    > End With
    > *************** *************** *************** *********
    >
    > I basically want the same sort of thing except from a table.
    >
    >
    > Thanks for any help
    >
    >
    > Mat
    >[/color]
    What is SchoolDB? A database, in Access, is file with an extension of
    MDB for the most part. The database usually contains tables, queries,
    forms, reports, macros, and modules.

    Let's say you have an MDB called SchoolDB.MDB. In that database, you
    have a table called Students. You might do something like this
    Dim rst As DAO.Recordset
    set rst = Currentdb.Openr ecordset("Stude nts",dbOpenDyna set)
    With rst
    ....
    End With

    Comment

    • Mat

      #3
      Re: Query into VBA

      Its a table. But I need to open a Query and sort through the data with
      code.

      Mat

      Comment

      • salad

        #4
        Re: Query into VBA

        Mat wrote:
        [color=blue]
        > Its a table. But I need to open a Query and sort through the data with
        > code.
        >
        > Mat
        >[/color]
        What's the diff between a query and a table? If it craps out, use
        "dbopendyna set" instead of "dbOpenTabl e"

        I do this all the time
        Dim r As Recordset
        Dim strSQL As String
        strSQL = "Select * From Employees"
        set r = currentdb.openr ecordset(strSQL ,dbopensnapshot )

        If snapshot, the result is not updateable. If dunaset, it's updateable.
        Of course, queries like a Totals query (using groupby) aren't updateable .

        Comment

        • Mat

          #5
          Re: Query into VBA

          Fantastic, thought it was going to be complicated.

          Found some stuff on passing paramiters in

          qdf.Parameters( 1) = [Forms]![invoice generation]![pass value]

          And together at last this makes sence

          Thanks for your help


          Mat

          Comment

          Working...