Results 1 to 11 of 11
  1. #1
    lynnmc26 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    18

    Autopopulate field

    I would like to have a field autopopulate (date field) when a checkbox is selected 'true'


    Fields are:

    FolderBCCheck-In (checkbox field)
    Check-InDate (date field)

    I need the check-inDate field to populate Date() when the FolderBCCheck-In field is checked.

    I assume it is VBA code to the AfterUpdate (Event procedure). Just having trouble getting the right code.

    Can someone assist?

    Thanks

    Lynn

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You want it to populate with the current date but only when that box is checked, so Default Value not suitable?

    You are doing data entry on a form? For a checkbox probably have better luck with the Change event. The date field is included in the form's RecordSource? Try:

    If Me.checkbox = vbTrue Then
    Me.datetextboxname = Date() '(or Me!datefieldname = Date())
    Else
    Me.datetextboxname = Null
    End If
    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
    lynnmc26 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    18
    Hi There
    yes , data entry on a form.
    OK - I will try the change event
    yes - included in the recordsource

    I will try - thanks
    Lynn

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If you don't want users changing the date value, better set Locked Yes and TabStop No.
    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.

  5. #5
    lynnmc26 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    18
    The date doesn't seem to be autopopulating with this? I must be doing something wrong....
    I placed the Code

    Option Compare Database
    Private Sub CheckInDate_Change()
    If Me.FolderBCcheckin = vbTrue Then
    Me.CheckInDate = Date '(or Me!datefieldname = Date())
    Else
    Me.CheckInDate = Null
    End If
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Should be the Change event of the check box, not the date box.
    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.

  7. #7
    lynnmc26 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    18
    I must just be tired or don't get this because I don't see the Change event for the check box and the () disappears after the Date and still is not autopopulating

    I am struggling - sorry - just an intermediate when it comes to VBA Code

    Anything else you can tell me that would get through to me?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Sorry, been a while since I used checkbox and relied on memory so had to just now look at one. Right, no Change event. Seems I had issues with AfterUpdate in past but just tested both Click and AfterUpdate events and both worked. So take your pick.
    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
    lynnmc26 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    18
    So this would be the one? (before I try this again) - Question - why does the () disappear after = Date?

    Private Sub CheckInDate_Click()
    If Me.CheckBox = vbTrue Then
    Me!FolderBCCheckIn = Date
    Else
    Me.FolderBCCheckIn = Null
    End If
    End Sub

  10. #10
    lynnmc26 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    18
    I got this to work

    I used:

    Private Sub FolderBCCheckIn_Click()
    If MyFolderBCCheckIn = Yes Then
    Me.CheckInDate = Date
    End If
    End Sub

    Thanks - SOLVED!!

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Date is a reserved word and a function without arguments in Access/VBA, so is Now(). Why they built it so VBA drops the parens from Date and not Now is a mystery.
    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. Autopopulate field
    By nancym in forum Forms
    Replies: 10
    Last Post: 11-07-2011, 09:53 AM
  2. autopopulate not working
    By slimjen in forum Forms
    Replies: 7
    Last Post: 09-16-2011, 01:38 PM
  3. Replies: 1
    Last Post: 06-21-2011, 03:34 AM
  4. Replies: 9
    Last Post: 09-23-2010, 10:42 AM
  5. Autopopulate NOT allowing overwrite
    By ChrisCione in forum Forms
    Replies: 8
    Last Post: 09-03-2010, 06:29 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