+ Reply to Thread
Results 1 to 13 of 13

Add new record to end of table

  1. #1
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Add new record to end of table

    With the following code when I a new record is added it is added at the top of the table, how can I get the record added after all the existing records?


    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  2. #2
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: Add new record to end of table

    This isn't the answer, however it may give you some ideas.

    If you look at the Northwind Db example(guessing you are using 2007). The purchase order module and recordsetwrapper class will show you some examples.

    I hope this helps some.

  3. #3
    Registered User
    Join Date
    03-20-2008
    Location
    Buffalo, NY USA
    Posts
    43

    Re: Add new record to end of table

    Your code doesn't necessarily add it to the top of the table. It probably appears that way based on how the table is sorted. You can either change the saved sort that is on the table (if you have an autonumber, sort ASC on that) or add an order by clause in any subesequent querying you do on the table.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Add new record to end of table

    split_atom18

    I actually have 2003 & the IT department will not give me access to the example databases

    Thanks for your reply


    bhill

    The table is not sorted and the new entry always appears as the 1st entry

    I know that I can sort when using queries but as I use a form that is directly linked to the table to view the records - so sorting a query is not an option

    I need the newest entry to always be the last record in the table,
    At present the newest entry is 1st , it then runs oldest to the 2nd last newest

  5. #5
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: Add new record to end of table

    If you hit the F5 key to refresh the form does it move to the bottom?

    If so add
    "Call Refresh" to your code.

    I am trying to recreate what is happening to you so I can test some things. However, not doing a very good job at recreating it.

    Hope this helps,

    Dan

  6. #6
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Add new record to end of table

    Hi mudraker,

    I know that I can sort when using queries but as I use a form that is directly linked to the table to view the records - so sorting a query is not an option.
    Not wanting to be pedantic about this, but wouldn't your situation be an ideal reason to "have" a query between your table and form? Is there a reason why you MUST link your form directly to your table?

    Cheers,
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  7. #7
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Add new record to end of table

    split_atom18

    Even when I open & look at the table manually the newest entry is always the 1st entry in the table.

    ConneXionLost

    I am self taught & I am still at the early days of learning - & may not have learnt the best way to do this.

    I extract data from a master table to a secondry table - this is done via 1 of 30 sql vba sql statements.

    By having the data in a secondry table I can change entries without affecting the main database - this gives me the option of saving or discarding the changes I have made

  8. #8
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: Add new record to end of table

    In you control source field on your form put the following, with you fields.

    SELECT [tbExtractedMeterDB].ID, [tbExtractedMeterDB].[Customer ID] FROM [tbExtractedMeterDB] ORDER BY [tbExtractedMeterDB].ID;

    Basic break down.

    Select (List fields here using a "," to seperate each field in the table you want to display) From [table name] ORDER BY Fields to Asc

    So if you have 5 fields you want to display in your table. Giving your fields numbers 1-5. And you want to order them by field 3.

    SELECT [tbExtractedMeterDB].[1], [tbExtractedMeterDB].[2], [tbExtractedMeterDB].[3], [tbExtractedMeterDB].[4], [tbExtractedMeterDB].[5] FROM [tbExtractedMeterDB] ORDER BY [tbExtractedMeterDB].[3]

    Hope this helps,

    Dan

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add new record to end of table

    mudraker

    The position of a record in an Access table should have no bearing.

    If you are relying on the position then I think you are going to face problems.

  10. #10
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: Add new record to end of table

    Still having problems?
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the "Star" and adding to my reputation, Thanks!

  11. #11
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Add new record to end of table

    I have not had much time to look at it

    Still having problems at the moment
    I may need to build a query that pulls all data from the table and then set the from to use the query

  12. #12
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: Add new record to end of table

    Quote Originally Posted by mudraker View Post
    I have not had much time to look at it

    Still having problems at the moment
    I may need to build a query that pulls all data from the table and then set the from to use the query
    That is basically what my explanation is.

    You can click the ... button next to the control source of the form and basically embed the query into the form. It will give you an ouput like I posted above.

    Let me know if you need anymore help,

    Dan

  13. #13
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Add new record to end of table

    split_atom18

    Looks like you pointed me in the right direction

    I have placed the following in the record source field
    Please Login or Register  to view this content.
    and tthe following in the Order By field
    Please Login or Register  to view this content.
    The above appears to give me what I want
    As form & datadbase is still being built, I have not fully tested it.


    Thanks for your assistance

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1