Results 1 to 13 of 13
  1. #1
    Join Date
    Jul 2007
    Posts
    9

    Question Unanswered: Change default date for records on the fly

    Hi Forum Members,
    I need to create a simple way for a data entry person to change the default date for records on the fly.

    She is entering many rows of data with a common date. Then the date changes. On average a sequence of a particular date may run from 1 to 25 to 30 or more rows.

    I don't want her to have to manually type in a sequence of 30 identical dates but at the same time I don't want anyone going to the design view of the form to change the default value for the field.

    Any simple suggestions that are easy to implement.

    Thanks for any help

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Try this in the after update event of the control:

    Me.ControlName.DefaultValue = Me.ControlName
    Paul

  3. #3
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    I was needing to do the same thing, but I get an error.
    Ryan
    My Blog

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    There are probably people smart enough to help without knowing what the error is, but I'm not one of them. It worked for me in a test.
    Paul

  5. #5
    Join Date
    Jul 2007
    Posts
    9
    Hi pbaldy
    Thanks for the reply. I tried it and it worked to an extent. The date changed fine but it was stuck on December 30, 1899 after the initial entry. When I clicked on the field it changes to 12:05:01 AM. I don't have a clue.
    If I get it to work correctly this would be an ideal solution.
    Thanks again.

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I have a clue, but it doesn't get me far. That's basically a date of zero. When you enter a date:

    7/19/07

    it's doing division on it instead of seeing it as a date (for the default value anyway). I'll try and find a way around that. There's this if it helps:

    http://allenbrowne.com/ser-24.html

    but it seems more complicated than you really need.
    Paul

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Me.ControlName.DefaultValue = Me.ControlName

    would work for a numeric field but not for a text field.

    For a text field you have to do

    Me.ControlName.DefaultValue = """" & Me.ControlName & """"

    and Access apparently requires this for a date as well!

    I would have thought if it was one or the other, a date would have to be treated like a number, but apparently not! This works for me:

    Code:
    Private Sub DateField_BeforeUpdate(Cancel As Integer)
      DateField.DefaultValue = """" & Me.DateField & """"
    End Sub
    That's with the field defined in the table as a date and formatted short date in the form.

    Linq
    Last edited by Missinglinq; 07-19-07 at 21:17.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Good to know, Linq. For grins I tested and this also works for text and date types:

    Me.ControlName.DefaultValue = Chr(34) & Me.ControlName & Chr(34)

    for people like me who don't like the look of all the quotes run together.
    Paul

  9. #9
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    The #$%^ things drive me nuts, too! At my advanced age I can't tell what's what eyeballing them! I'll remember Chr(34) !
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  10. #10
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Not to throw something in but would this also work?

    me.DateField.DefaultValue = "#" & Me!DateField & "#"
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  11. #11
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    'Deed it would! I tried

    me.DateField.DefaultValue = #Me!DateField#

    first off, but Access, of course, squawked!

    As my signature says, what I like about Access is "There's always more than one way to skin a cat!"
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  12. #12
    Join Date
    Jul 2007
    Posts
    9
    Thank you very much everyone who responded. Your solutions worked beautifully. The data entry person and I are happy. Thanks again.

  13. #13
    Join Date
    Jul 2007
    Posts
    1
    Hi. I am new here and found this place on google while beating my head into a wall on a similar problem...

    Unfortunately, the solutions here have not worked for me and I was hoping to get some further insight. Here's what I am doing:

    I am using Access 2007. Similar to above, I have a data entry form that with require numerous entries for the same variable date. I have created a unbound text box formatted as a short date and I am hoping to use this to set the default date for new records. I have tried setting the default value property of the control though the properties window and as an after update event of the texbox in all the manners descibed above with no luck. I inevitably get a "#Error" when I create a new record?

    Help!?! Please!?!

    Edit: Nevermind. Found my problem and it was betweent the chair and the keyboard. I am an idiot. Thanks anyway for being the only forum on the net to address this question!
    Last edited by damian0; 07-26-07 at 15:13.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •