Results 1 to 15 of 15
  1. #1
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53

    Getting last entry of field for default value in form

    I have a form, shown in the pic below, that contains combo boxes which i want to get the last entry of their field for the default value. I want to do this because the user is required to input many records and often the 'Tendering Name' and 'Item Type' are the same, thus reducing the time to enter the data into the form.

    Does anyone know how i can do this? I hope the pic is ledgible.



    Click image for larger version. 

Name:	Untitled.png 
Views:	41 
Size:	25.8 KB 
ID:	20570




  2. #2
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    The form is Saving the records fine using the 'Add Item to Data' button. I want to be able to click 'Next Item' and have the form go to the next record, with the Tender Name and Item Type already entered using the same values as the previous entry. Thanks.

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

  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
    Paul's given you a link to the standard method, but FYI there is a keyboard shortcut that enters the same data, for a Control, that was last input into the Control:

    <Ctrl> + <'>

    Note that this even works if the Form is closed and later reopened!

    Welcome to the forum!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    Thanks for the help, I have finally got a working solution. Here is the code:


    Private Sub NextItem_Click()

    Const cQuote = """" 'Thats two quotes
    Me!cboTenderName.DefaultValue = cQuote & Me!cboTenderName.Value & cQuote


    Const cQuote1 = """" 'Thats two quotes
    Me!cboType.DefaultValue = cQuote1 & Me!cboType.Value & cQuote1
    DoCmd.GoToRecord , , acNewRec


    End Sub


    You guys rock!

  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,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    Following on from this, i'm trying to get the code to stop from going to the new record if any of the fields are Null.
    Here is my current code: although i suspect the exit function is not the command im after.

    Private Sub NextItem_Click()

    If [cboItem] = Null Then
    MsgBox "Please enter the Item Description "
    Exit Function

    ElseIf [Quantity] = Null Then
    MsgBox "Please enter the Quantity "
    Exit Function

    ElseIf [cboUOM] = Null Then
    MsgBox "Please enter the Unit "
    Exit Function

    ElseIf [UnitPrice] = Null Then
    MsgBox "Please enter a Unit Price "
    Exit Function

    End If

    Const cQuote = """" 'Thats two quotes
    Me!cboTenderName.DefaultValue = cQuote & Me!cboTenderName.Value & cQuote

    Const cQuote1 = """" 'Thats two quotes
    Me!cboType.DefaultValue = cQuote1 & Me!cboType.Value & cQuote1

    DoCmd.GoToRecord , , acNewRec

    End Sub

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It's a sub, not a function, so

    Exit Sub
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    This has solved my error thanks, however when i test the form it still goes to the next record despite me leaving one of the fields Null. Why does the If loop fail to stop this?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That isn't a valid way to test for Null. Try

    If Len(Me.cboItem & vbNullString) = 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    Perfect, you're a legend. Saving me so much time.

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

  13. #13
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    How do I set the default value for these fields on the next record?

    I changed the line to DoCmd.GoToRecord , , acNext however I now need to set/update the default value on the next record from a Null value to the value from the previous record?

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How about this, in the after update event of the control?

    http://access.mvps.org/access/forms/frm0012.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    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
    Paul gave you a link for doing this...and you've posted code that does this, but here's a quick recap:

    You can use the AfterUpdate event of the Control holding your data to set the DefaultValue for the Field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each New Record.

    Code:
    Private Sub YourControlName_AfterUpdate()
       Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
    End Sub

    This syntax is valid for Text, Number, DateTime and Boolean Datatypes.

    You’ll need to do this for each Control that you want to ‘carry forward.’

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Last entry to open by default
    By MissLotus in forum Forms
    Replies: 6
    Last Post: 07-22-2013, 06:15 PM
  2. Replies: 7
    Last Post: 07-20-2013, 03:59 AM
  3. Default Value - Last Entry
    By jnb22019 in forum Programming
    Replies: 3
    Last Post: 04-20-2012, 08:14 AM
  4. Replies: 4
    Last Post: 01-27-2010, 12:39 PM
  5. Replies: 1
    Last Post: 02-10-2007, 10:21 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