Results 1 to 10 of 10
  1. #1
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53

    Default date value based on the value of other field

    Hi, I have a form, in which I want a default date value as "31.12.99" in a filed, if another field value is say "A". Otherwise, the date field value has to be blank. I would not like to use codes. Macros or expressions are ok.



    Requesting help please.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Expression in the date field:

    =iif(txtCode='A',"31.12.99",null)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Keep in mind this will not save value into table, just calculate for display.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53
    The above expression is not working, #Name? error is appearing in the filed.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Did you use actual name of your control or field? Show your actual expression used.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53
    =IIf([Seva item]="Shaswatha Pooja","31-12-99",Null)

  7. #7
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53
    The above expression I used in a form, default value property, the field [Seva Item] is also in the same form. By tab option, the earlier field is filled first. the date field is at 3rd tab option

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Not in DefaultValue, put in ControlSource.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Apr 2017
    Posts
    1,673
    Having formula in form control means, that this control is unbound, i.e. is not linked to field in source table (look June's post #3).

    Iif(..,"31-12-99", Null) returns not a date, but a string. Use Iif(..., DateSerial(1999, 12, 31), Null) instead (in case you are content with unbound control). You can then format the control in any date format you want.

    When you need the control to be bound to source table field (ContrlSource propery contais field name), you need an AfterUpdate event of [Seva item] control, which checks, is date control empty and [Seva item] control = "Shaswatha Pooja", and when yes, then sets date control's value = DateSerial(1999, 12, 31)

  10. #10
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53
    Thanks a lot

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

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2017, 07:30 PM
  2. Replies: 9
    Last Post: 02-06-2017, 11:56 AM
  3. Field to display last Friday's date by default
    By lsmcal1984 in forum Forms
    Replies: 11
    Last Post: 10-07-2013, 12:05 PM
  4. Replies: 5
    Last Post: 11-18-2012, 01:27 PM
  5. Replies: 4
    Last Post: 12-21-2011, 02:45 AM

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