How to move last while inserting into a table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bibek24
    New Member
    • Sep 2008
    • 18

    How to move last while inserting into a table?

    Hi all,

    I am using the following piece of code to insert records into a table.Sometimes it is inserted at the bottom,sometime s at the middle and sometimes at top of the table.

    [HTML]Private Sub Command383_Clic k()
    Dim Db As Database
    Dim rs As DAO.Recordset
    Dim strsql As String
    txtMessageTest = ""
    Set Db = CurrentDb
    Set rs = Db.OpenRecordse t("casedetails" , dbOpenDynaset)
    rs.MoveLast
    DoCmd.OpenForm "frmZoomTes t", , , , , acDialog
    If Not txtMessageTest = "" Then
    strsql = "insert into casedetails (casenumber,cas edetails,curren tuser) values(" & Val(Me!CaseNumb er) & ",'" & txtMessageTest & "','" & gfncCurrentUser & "')"
    Db.Execute strsql
    subCaseDetails. Requery
    Else
    MsgBox "cancel Selected"
    End If
    rs.Close
    Set rs = Nothing
    Set Db = Nothing[/HTML]

    Need to know what should be done to insert records always at the last?

    Thanks,
    Bibek
  • DonRayner
    Recognized Expert Contributor
    • Sep 2008
    • 489

    #2
    Since MS Access does not apply record numbers to any records that you create, the table will be not be in the order created but in the order sorted.

    If you want everything to appear in the order that it's entered you will have to either

    1. add a primary key thats set to a sequential autonumber and sort on that or

    2 add a date/time field with it's default set to now() and sort on that.

    Don

    Comment

    Working...