Results 1 to 3 of 3
  1. #1
    crewjones is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    1

    Static value in field

    I have a DB with some data already entered into the "Date Checked Out" field (this is for an equipment inventory DB)


    I want to modify the db so that when a user opens the form, today's date with be the default value and that value will not overwrite the already existing date for whatever records already have a date entered.

    I added the existing field into the form and entered the expression in the default value field
    IIF([DateChecked] Is Null, Date())

    I thought this would translate to If the Date Checked out field is Null value, then enter today's date.

    But It is not displaying today's date as the default value.

    thanks

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Default value is only going to take effect for a new record. For a new record, it will always be null, so you don't need the IIF. If you're wanting an existing record that is Null to have its value updated, then you'll need to use an event to trigger the recalculation of that field.

    I've forgotten all the ins and outs of what events happen in what order at the end of updating a record. June7 or rpeare may have that in the front of their brains and chime in.

    Possibly the BeforeUpdate Event of the form?

    You'd have VBA to check the value of the control that was bound to your DateCheckedOut
    Code:
    If IsNull(txtDateChecked) Then
       txtDateChecked = Date()
    End If
    You'll have to decide whether you want a date or a timestamp, and code accordingly.

    Can you tell us specifically under what circumstances you do want a record with null checkout date to be updated, and when you do not? Think of all the different ways that a user could leave the screen, or leave the record, after updating or not updating the record. Decide the behavior you want, and that will determine how many events you need to put code in. (If me.dirty, etc)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    I usually use the OnCurrent event if I want the field to populate when existing record is initially opened.
    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.

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

Similar Threads

  1. Control within Static Text
    By mcrow in forum Reports
    Replies: 3
    Last Post: 06-07-2012, 10:41 AM
  2. Replies: 10
    Last Post: 08-18-2011, 04:27 PM
  3. Are reports static?
    By Buakaw in forum Reports
    Replies: 3
    Last Post: 03-22-2011, 10:24 AM
  4. Static Array Issue
    By Tinarad in forum Programming
    Replies: 1
    Last Post: 03-01-2011, 01:14 PM
  5. Create a static table
    By Alexandre Cote in forum Programming
    Replies: 2
    Last Post: 09-13-2010, 10:59 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