Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41

    Default Value by formula

    Is there a way to set the default value of a field to the previous record's value?

    So, if I have:
    Start Stop
    1 2
    2 3
    3 4



    etc... I want to pull the Start from the previous Stop so I don't have to enter the same thing twice.

  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,530
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41

    But..

    I'm not trying to set the value to the same field value from the previous record, I'm trying to set it to a different field's value in the previous record. I'm having a hard time understand that code and similar codes I've found while researching my question. Unfortunately I'm not very good with VBA.

  4. #4
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    So, I know how to get into VBA but which event am I adding the code to and on which control? Is it on the form or the text box? I am very confused. Any assistance will be greatly appreciated.

  5. #5
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    I know this shouldn't be difficult but I just don't know where to begin. Isn't there anyone who can point me in the right direction?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You can set any field:

    me!Control.DefaultValue = cQuote & me!SomeOtherControl.Value & cQuote

    I've tested it in either the before or after update event of the control, can't remember which offhand.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    Thank you. I'm gonna try that and see what happens

  8. #8
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    My controls are named txtStartTime & txtEndTime. I tried putting the code below in both the before and after update events of the txtStartTime control and I got nothing.

    const cQuote="""" 'Thats two quotes
    me!txtStartTime.DefaultValue = cQuote & me!txtEndTime.Value & cQuote

    I am so clueless on this.

  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,530
    Since it's dependent on the end time, I'd use the update event of end time so that when it changes your value changes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    WAHOOO!!!! That was it! thank you so much! I'm extactic.

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

  12. #12
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    Uh Oh! I have an error in my logic because of the way I do data entry. So I'll need to modify this somehow so that if I update the EndTime of a record that update will go to the StartTime of the next record not just of the new record.

    Let me see if I can explain this.

    So... when I do data entry it is faster/easier for me to go down than across using the enter key. If my data looks like this for example:

    Activity| StartTime| End Time|
    100 | 0600| 0700|
    101 | 0700| 0800|
    102 | 0800| 0900|

    I'll type all the activities first then the first StartTime, then the EndTimes. So, the records are already created which means my code doesn't work in the way that I have it because it's only update new records.

    So, what do I need to do so that I actually am updating pre-existing records. I saw a post on here that started to address this I think but there was no solution.
    https://www.accessforums.net/access/...ata-11171.html

  13. #13
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    I'd want my code to work out this way regardless of how I do data entry anyway, because there are times when I need to change an EndTime and I would want that to automatically update the corresponding StartTime.

  14. #14
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    wrong thread

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Sorry, I lost track of this thread. If you have some order of records that can be relied upon, it wouldn't be hard to open a recordset and get the next record, so when you change the end time field it will update the next start time. The key is to be able to identify that next record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error in Formula
    By TheProfessorIII in forum Access
    Replies: 9
    Last Post: 03-21-2011, 05:50 AM
  2. SQL Formula to Sum Itself
    By Scorpio11 in forum Access
    Replies: 1
    Last Post: 02-19-2011, 11:22 AM
  3. Need help creating a formula
    By Jimmy0291 in forum Queries
    Replies: 1
    Last Post: 01-17-2011, 12:12 PM
  4. Formula
    By hschrunk in forum Access
    Replies: 3
    Last Post: 05-18-2010, 01:40 PM
  5. formula on report??
    By dike969 in forum Access
    Replies: 0
    Last Post: 03-05-2007, 01:58 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