Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2013
    Posts
    4

    Unanswered: Getting a parameter from a query into a variable.

    How can I use query parameters in local variables ACCESS platform.
    For example I have a table with a field that contains a list of files to me, I want to access all the files (preferably together) and delete them / update it. Hence, I would like to query the parameter into a local variable and then to work with.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Use a DELETE query (to delete) or an UPDATE query (to update)... or is there something I missed in your explanation?
    Have a nice day!

  3. #3
    Join Date
    Apr 2013
    Posts
    4
    I want to get the query to a variable, for example I have some txt files on the computer, I have to put all the different data file,
    Before I start I need to insert data to initialize the file, then put all its data file ...
    I do not want to write any code file name individually ... But want to retrieve them out of a table into a local variable, but I do not kn do it.
    Hope it's clear enough that the text here translated through Google.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. If you have a single value to retrieve from the table, Use the DLookUp function:
    Code:
    Dim Criteria As String
    Criteria = "SomeColumn = SomeValue"
    Value = DLookUp("Column Name", "Table Name", Criteria)
    2. If there is a whole set of values to be retrieved sequentially, open a RecordSet:
    Code:
    Dim rst As DAO.RecordSet
    Dim Criteria As String
    Criteria = "SomeColumn = SomeValue"
    Set rst = CurrentDb.OpenRecordSet("TableName", dbOpenSnapshot)
    With rst
        .FindFirst Criteria
        Do Until .NoMatch = True
            Value = !FieldName
            ' 
            ' Do whatever you want with Value.
            '
            .FindNext Criteria
        Loop
        .Close
    End With
    Set rst = Nothing
    You can also open a RecordSet limited to a subset:
    Code:
    Dim rst As DAO.RecordSet
    Dim strSQL As String
    strSQL = "SELECT FieldName FROM TableName WHERE SomeColumn = SomeValue;"
    Set rst = CurrentDb.OpenRecordSet(strSQL, dbOpenSnapshot)
    With rst
        Do Until .EOF = True
            Value = !FieldName
            ' 
            ' Do whatever you want with Value.
            '
            .MoveNext
        Loop
        .Close
    End With
    Set rst = Nothing
    Have a nice day!

Posting Permissions

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