Results 1 to 3 of 3
  1. #1
    Cottonshirt is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2018
    Posts
    116

    default value for unbound control on form

    good morning,

    I have an unbound form. it has two controls, both of which are dates, [fromdate] and [todate]
    the dates are used as the criteria for a query. the query is displayed in datasheet view (not on the form).

    I currently have [fromdate] set with a hard coded default date #04/01/1850# which displays as 4 Jan 1850

    what I want to do is change the default to the date of the earliest record in the database.
    fortunately, this is already calculated in a query that is the source for a report, so the date I want is qry_eventcount2.start

    if I enter this as the default value property of the control I get the #Name? error.

    Googling this error I came across the following:

    "typically, #Name? error occurs when the name of the control is a field in the recordsource, and controlsource begins with ="



    since my form is unbound and neither edits nor enters data it has neither a recordsource nor a controlsource. so we have to pay attention to the word, "typically," at the beginning. which means, often, but not always.

    so I look elsewhere for assistance and all the web pages I looked at describing the setting of a default value for a control use some form of the following?:

    "The default value will appear in the control when you add a new record with the form."

    they don't seem to consider that forms can be for things other than data entry. so I started to wonder whether it is even possible for an unbound control to have anything other than a hard coded default value. so I changed the default value property to =Date(), and that worked, it displayed today's date. but that comes from the computer rather than from the database.

    so, my question is:

    can a control on an unbound form have as its default value property data directly from the database, and if so, how do I do that?



    many thanks,



    Cottonshirt

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Should be possible. Try using DMin() function. See: https://www.techonthenet.com/access/...omain/dmin.php
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Cottonshirt is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Feb 2018
    Posts
    116
    thank you,

    that worked a charm.

    I had to think about the criteria, but this worked

    DMin("start","qry_eventcount2","IsNull([start])=0")


    thank you very much indeed.

    Cottonshirt

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

Similar Threads

  1. Unbound Combo on form to show a default value
    By d9pierce1 in forum Forms
    Replies: 11
    Last Post: 04-13-2019, 01:14 PM
  2. retrieve data from unbound control on form
    By Abacus1234 in forum Queries
    Replies: 6
    Last Post: 08-04-2015, 05:31 PM
  3. Replies: 3
    Last Post: 06-17-2015, 01:16 PM
  4. Replies: 5
    Last Post: 09-01-2014, 08:22 AM
  5. Form unbound field control problem?
    By justphilip2003 in forum Forms
    Replies: 22
    Last Post: 04-18-2013, 03:39 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