Results 1 to 4 of 4
  1. #1
    bburton12@comcast.net is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    11

    How do I enter the result of a query into as the default value of a field in my table

    Originally I had populated the following as my control source:


    Code:
    =DLookUp("version","qryversionlist")
    . "Version" is from tblVersion, not my main table. The problem is that I need a field in my main table as the control source, and apparently, I can't have both a field and the dlookup as the control source.

    qryversionlist brings up the most recent version number:

    Code:
    SELECT TOP 1 version
    FROM tblVersion
    ORDER BY id DESC;
    I need that value to be in the default value for my field on my main table so it will always show up on my form, but can't figure out how to do it. I read that you can do it with a query, but how do I enter the query into the table field?


    Thank you,
    Brad

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    So Version is a field in the table that is the recordsource of your main form.
    In that case, version should be present in existing records, except for a new record.
    So try this:
    Code:
    Private sub Form_Current()
        if me.newrecord then
            me.version = dlookup("version","qryVersionList")
        end if
    end sub

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    And you don't actually need the query; you could use DMax() to pull the highest version.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    bburton12@comcast.net is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    11
    Thank you. I'll look at it.

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

Similar Threads

  1. Replies: 4
    Last Post: 05-14-2018, 06:05 PM
  2. If query result is empty, put 0 as default value
    By themushroomking in forum Queries
    Replies: 8
    Last Post: 07-18-2017, 09:07 AM
  3. Replies: 20
    Last Post: 03-30-2014, 12:18 PM
  4. Replies: 2
    Last Post: 11-27-2013, 05:24 PM
  5. Enter query result in a form textbox
    By Damo10 in forum Forms
    Replies: 2
    Last Post: 06-30-2013, 06:43 PM

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