Results 1 to 3 of 3
  1. #1
    ismafoot is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    May 2018
    Posts
    22

    Question Query to select a specific record from a Table

    Hi,

    I linked a table to a html source to extract currency exchange rates.
    The table contains 6 columns. The first column lists the countries and the rest are dates with the last column being the most recent.


    Ex: field 1 field 2 field 3 ...
    USD 1.287 1.286 ...
    EUR 1.501 1.506 ...
    I need to have the value of the US dollar of the most recent date at all times (every day).

    What I did is create a query with the following SQL statement:
    SELECT Field1, Field6
    FROM [exchange]
    WHERE Field1="Us dollar";

    Field1=Country names column
    Field6=Today's currency rate column.

    My main menu form needs to display the rate of the current date so I created a text box button but im not sure how to extract that specific record.
    Furthermore, it seems the steps I took could easily be reduced but I am just not sure how.
    I wonder if the query updates with the new value each day as well.

    Thank you in advance for your help guys.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    i put the SQL in a query, so you must make or change the query name: qsGetLatestData

    Code:
    Public Sub BuildSql()
    Dim tdf As TableDef
    Dim qdf As QueryDef
    Dim sSql As String, sFld As String
    
    Set tdf = CurrentDb.TableDefs("exchange")
                'get the last field name (most recent date)
    sFld = tdf.Fields(tdf.Fields.Count - 1).Name
    
        'use field in query
    sSql = "SELECT [Field1], [" & sFld & "] FROM [exchange] WHERE [Field1]='Us dollar'"
        'save sql as the query
    Set qdf = CurrentDb.QueryDefs("qsGetLatestData")
    qdf.SQL = sSql
    qdf.Close
    DoCmd.OpenQuery qdf.Name   'open the query
    
    Set tdf = Nothing
    Set qdf = Nothing
    End Sub

  3. #3
    ismafoot is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    May 2018
    Posts
    22
    I need VBA for this ? I'm confused...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 04-27-2016, 04:06 PM
  2. Replies: 3
    Last Post: 08-26-2015, 12:58 AM
  3. Replies: 32
    Last Post: 05-23-2013, 04:16 PM
  4. Replies: 12
    Last Post: 08-21-2012, 02:40 PM
  5. Replies: 3
    Last Post: 02-28-2012, 12:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums