Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Posts
    1

    Unanswered: Retrieving a Record from a Query

    I have managed to open a Query through a Macro in Access, and i can traverse the records too, via the

    DoCmd.GoToRecord acDataQuery, "Query Name"

    command.

    However, I was wondering if there is a way I could actually get the current record information in a String, so that I can write this string to a file.

    i.e. My high level pseudo code is:

    while(No more records)
    curRecord = getCurrentRecord; // HOW DO I DO THIS ?
    write CurRecord to a textfile;
    goto nextRecors.
    end

    Any insight will be highly appreciated !

    Thanks,
    bobby

  2. #2
    Join Date
    Jan 2003
    Location
    Dordrecht, The Netherlands
    Posts
    95

    Re: Retrieving a Record from a Query

    You can do this by using a recordset, like this:

    Sub GetStrings()
    Dim DB As DAO.Database, RS As DAO.Recordset

    Set DB = CurrentDb
    Set RS = DB.OpenRecordset("Query Name")

    Do Until RS.EOF
    'FieldName stands for the field name in the query that you want
    'to retrieve; in this case it is simply shown in the output window
    Debug.Print RS.Fields("FieldName")
    RS.MoveNext
    Loop

    Set RS = Nothing
    Set DB = Nothing

    End Sub

    Originally posted by bobbyg9
    I have managed to open a Query through a Macro in Access, and i can traverse the records too, via the

    DoCmd.GoToRecord acDataQuery, "Query Name"

    command.

    However, I was wondering if there is a way I could actually get the current record information in a String, so that I can write this string to a file.

    i.e. My high level pseudo code is:

    while(No more records)
    curRecord = getCurrentRecord; // HOW DO I DO THIS ?
    write CurRecord to a textfile;
    goto nextRecors.
    end

    Any insight will be highly appreciated !

    Thanks,
    bobby

  3. #3
    Join Date
    Nov 2002
    Posts
    19
    you can use GetString.

    http://www.devguru.com/Technologies/...getstring.html

    has a good overview of what it does.

    Essentially, stringvar=RST.Getstring(arguments) will return a string with the column and row delimiters whatever you wish. You can then work on this string with the normal string utilities.


    Good Luck
    DerFarm
    It IS as bad as you think
    and they ARE out to get you

Posting Permissions

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