Results 1 to 9 of 9
  1. #1
    teirrah1995 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Sep 2010
    Posts
    35

    Command button to change value of other field

    Hi. I'm sorry if this is in the wrong forum- it's my first time here, and my first time doing anything serious with Access.

    What I'm looking for is dead simple, in theory, and I've done quite a few more complicated things than this. I want a command button that, when clicked, will change a field to today's date. This is the first thing, and I haven't been able to find any way to do it, which is ridiculous really.
    The second thing is that I want another field to come up with today's date + 6 months or so. Ideally, I'd like some sort of option of 6 months, 1 year, or 2 years on a menu or something, but I don't know if that's beyond what Access (and I) can do.
    Any help on any or all of these things would be really appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    Welcome to the site. The command button is easy:

    Me.Whatever = Date()

    replacing Whatever with the name of the textbox you want to change. You can use that along with the DateAdd() function to accomplish the second goal. You can use text or combo boxes to allow the user to select the values if you want.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    Oh, and what I posted was VBA code. If you haven't used it yet:

    http://www.baldyweb.com/FirstVBA.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    teirrah1995 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Sep 2010
    Posts
    35
    Is VBA similar to the expression builder? I'm fairly familiar with that. Thanks a lot for the reply, and it was much quicker than I expected. I'll give that a try out right now.

    Sorry, I'm very new to this. How would I phrase the dateadd() function? Could you give an example please?

    And it didn't seem to recognise "Me.". Was I supposed to replace that with the command button's name? Thanks for helping a young newb ^^

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    I would start by looking in Help at the DateAdd function; it should have a complete description and examples. "Me" is only valid in VBA code (which is not the same as the expression builder, though they share many things). It is a shortcut to refer to the object containing the code (object meaning the form or report).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    teirrah1995 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Sep 2010
    Posts
    35
    Thanks for the help. When I put Date() in the VBA thing, it always gets rid of the () by the time I go back to it. Is there a way to keep it there? Am I phrasing it wrongly?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    I've seen VBA strip the parentheses but it will still work. If it's not, you may have a field named Date that is confusing Access. If so, the fix is to disambiguate and use:

    Me.Whatever = VBA.Date()
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    teirrah1995 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Sep 2010
    Posts
    35
    Wow, that worked perfectly! I've been clicking buttons for weeks trying to get them to work. Thanks a lot!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Changing Field Values with Command Button
    By avarusbrightfyre in forum Access
    Replies: 1
    Last Post: 08-22-2010, 12:48 PM
  2. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  3. Command Button
    By nashr1928 in forum Forms
    Replies: 2
    Last Post: 07-05-2010, 08:02 PM
  4. Command Button Help!
    By arthura in forum Programming
    Replies: 3
    Last Post: 06-30-2009, 12:55 PM
  5. Replies: 2
    Last Post: 03-10-2009, 05:14 PM

Tags for this Thread

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