Results 1 to 11 of 11
  1. #1
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24

    Help with populating date in form...

    I have a subform. I want to create an unbound date box in my main form that when I pick a date it will automatically fill it in for the date column in my subform when I enter in new data. I just don't want to have to manually put in the dates each time I fill out the subform because it will all be the same dates.



    Thank you

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Alternative and perhaps easier approach is to set the DefaultValue property of the control in subform. In the control BeforeUpdate event VBA procedure:

    Me.controlname.DefaultValue = Me.controlname
    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
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24
    Now if I change the date in unbound box in main form it should not change the dates already set in the subform correct?

    Thanks

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I'd use the AfterUpdate event of the Control holding your Date to set the DefaultValue for the Field, but the syntax June7 gave isn't quite correct. From that time forward, until you either manually change the Date or close your Form, the Date will be entered automatically in each New Record.

    Code:
    Private Sub DateControlName_AfterUpdate()
       Me.DateControlName.DefaultValue = """" & Me.DateControlName.Value & """"
    End Sub

    This same code is valid for Text, Number and Date Datatypes. Never tried it on a Yes/No Field!

    Linq ;0)>

  5. #5
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24
    So it would go in like:

    Me.txtNPDate.DefaultValue = """" & Me.txtNPDate.Value & """"

    This would help for another field too

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Good catch linq, syntax with apostrophe instead of twin quote marks also works:

    Me.DateControlName.DefaultValue = "'" & Me.DateControlName.Value & "'"
    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
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24
    I put that code into the afterupdate of the subform and nothing happens

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Code goes in TEXTBOX event.

    Either event seems to do the job.
    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
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24
    I am sorry but I am doing something wrong. Still not working. I placed the code in the TEXTBOX Date in the subform and still does not work. To be clear, I have a New Program Date box in the main form and a Date box in the subform. I put in the code: Me.txtNPDate.DefaultValue = """" & Me.txtNPDate.Value & """" in the Date box in the subform and nothing happens.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Our suggestion does not involve a textbox on the main form. It is not necessary. Open form, enter date in new record, code will set DefaultValue property of textbox. The code goes in the event of textbox on the subform.

    Me.subformtextboxname.DefaultValue = "'" & Me.subformtextboxname & "'"
    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.

  11. #11
    bishop0071 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    24
    That worked!!!! Thank you so much for your help!!!

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

Similar Threads

  1. Auto populating on a Form
    By Canadiangal in forum Forms
    Replies: 1
    Last Post: 03-28-2013, 04:54 PM
  2. Form / combobox not populating
    By Auracle in forum Forms
    Replies: 7
    Last Post: 09-20-2011, 11:01 AM
  3. Populating a sub form
    By claff319 in forum Access
    Replies: 2
    Last Post: 08-17-2011, 08:56 AM
  4. Auto populating date.
    By emccalment in forum Access
    Replies: 3
    Last Post: 02-19-2010, 11:00 AM
  5. Self-populating one form from another
    By winter in forum Forms
    Replies: 7
    Last Post: 08-03-2009, 08:02 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