Results 1 to 7 of 7
  1. #1
    ismith is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    39

    Need Help with inputting data in Form via database

    Hi.

    Ive got an unbound form which i have linked to my database.
    What im trying to do is when the form is open, it pre-fills with the last record that was entered into the databse.



    Now ive got it looking at the database and it does bring up the 1st record.

    What i cant figure out is how do i get it to look at the last record in the database.

    This is my code so far:

    Dim getTableRecord As DAO.Recordset
    Dim dbs As Database

    Private Sub form_load()

    Set dbs = CurrentDb
    Set getTableRecord = dbs.OpenRecordset("tblProduct")

    txtProdID.Locked = True
    txtDescription.Locked = True
    txtCategory.Locked = True
    txtSize.Locked = True
    txtQuantity.Locked = True
    txtPrice.Locked = True

    txtProdID.Value = getTableRecord("ProductID")
    txtDescription.Value = getTableRecord("Description")
    txtCategory.Value = getTableRecord("Category")
    txtSize.Value = getTableRecord("Size")
    txtQuantity.Value = getTableRecord("Quantity")
    txtPrice.Value = getTableRecord("Price")

    End Sub


    what that does atm is prefill the boxes but with the data thats on the 26th record. Got no idea why thats happening. So how do i get it to load the data thats on the last record??

    Thanks for the help..

  2. #2
    nicknameoscar is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2011
    Location
    Earlysville, VA
    Posts
    91
    What do you mean by "last record"? What the database thinks is the last record and what you think is the last record could be entirely different. You might need to write a query that sorts the records like you want. If you create a recordset with the records in the order you want then you could do:

    getTableRecord.MoveLast

    Hopefully I didn't totally miss the point of your question.

    Edit: Or you could write the query such that it puts the last record first in the recordset, then you could:

    getTableRecord.MoveFirst

    to be safe.
    Last edited by nicknameoscar; 12-09-2011 at 07:12 AM. Reason: clarify

  3. #3
    ismith is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    39
    what i mean is the last record that is entered into the database.

    Ive got an Add Product form which the user fills in and adds data to the database. What i want to do is take that data and output it in another form that shows the last product to be entered.

    Thats what im trying to do.

    Thanks..

  4. #4
    JenEveAle is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    15
    You could include an autonumber in your AddProduct form/table, then on the second form, filter by Max of that autonumber.

  5. #5
    JenEveAle is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    15
    Sorry... not filter by. I meant sort by and then use the move to first record.

  6. #6
    ismith is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    39
    Yes what ive got atm is my ProductID in my table is an autonumber increment. Which starts at 1 and goes up everytime a product is added.

    When i add a product in using my form ive created it does add into the database and goes up in the productID field.

    I do understand what you mean but could you show wm how to do it?

    thanks..

  7. #7
    JenEveAle is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    15
    ismith... did you get this answered? I had to be offline for a while. Sorry.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-29-2011, 04:11 PM
  2. Replies: 0
    Last Post: 02-27-2011, 04:21 PM
  3. Getting a database without the data
    By GRB in forum Access
    Replies: 5
    Last Post: 01-09-2011, 07:50 AM
  4. Inputting Free text in Form
    By maintt in forum Forms
    Replies: 2
    Last Post: 08-13-2010, 11:43 AM
  5. Replies: 15
    Last Post: 02-16-2010, 10: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