Results 1 to 7 of 7
  1. #1
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370

    If statement

    I have a date field that I would like to be updated to =Now() but only for new records.



    My guess is that I will need an if statement in the OnClick event in properties of that field.

    I tried making an if statement but was unsuccessful. Any help would be great!

    Thank you all!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,648
    Could set DefaultValue property to: Now()

    No code required.
    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.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the table design mode, select the date field.
    In the "DEFAULT VALUE" property row, enter =Now() .

    Now, anytime a NEW record is created, the current date and time will be automagically entered.

  4. #4
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Sorry, It doesn't have to be a new field, I only want it to update OnClick to =Now() if and only if the record doesn't have a date already in it.

    EDIT: ssanfu, I just noticed your typo, and it had me laughing..

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,648
    I don't think Steve did a typo, but was intentional word play.

    DefaultValue won't do anything to existing records.

    You want to set value of existing records? Could do this in one pass with an UPDATE sql action.

    Otherwise:

    If IsNull(Me!fieldname) Then Me!fieldname = Now()
    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
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sometimes when you are programming on the confuser, things automagically happen. It does what I tell it to do, not what I want it to do.


    I only want it to update OnClick to =Now() if and only if the record doesn't have a date already in it.
    Code:
    If IsNull(Me.Date_Control_Name) then
      Me.Date_Control_Name = Now()
    End if
    I used "Me.Date_Control_Name".... hopefully you took the time to rename the control. Access has the bad habit of naming a control the same name as the bound field. This can confuse Access.

    I always take the time to rename the control so I (and Access) don't (doesn't??) get confused.


    Or maybe
    Code:
    If Not Isdate(Me.Date_Control_Name) then
      Me.Date_Control_Name = Now()
    End if

  7. #7
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Thanks June7, That last statement is working for me.

    Thanks for your input as well ssanfu!

    EDIT: Thanks for marking it solved also :P I have that in my sig, yet I'm not even living up to it... it's a shame.

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

Similar Threads

  1. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  3. need a If /then statement
    By kmiszczak in forum Access
    Replies: 1
    Last Post: 04-12-2011, 01:51 PM
  4. Help with IF statement
    By mkallover in forum Programming
    Replies: 7
    Last Post: 01-04-2011, 04:47 PM
  5. Help with Iif statement
    By tmcrouse in forum Queries
    Replies: 2
    Last Post: 09-02-2010, 09:00 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