Solved

Adding New Record

Posted on 2006-10-22
7
139 Views
Last Modified: 2012-05-05
Hi Experts,

I have a form call frmdetails which displays all of the people in a table in a list box.  I have a form that adds new people to the table.  It only adds first, middle & surname.  Once the record is added, i then clear the original list on frmdetails then reapply the list with the new recorded, sorted by surname.

How do i get the list box to automatically select and go to the record i have just added?

Regards,

Andrew.
0
Comment
Question by:andrewl77
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17783718
Private Sub Command1_Click()
    Dim i As Integer
   
    List1.AddItem "def"
    List1.AddItem "abc"
    i = List1.NewIndex
    List1.ListIndex = i
End Sub
0
 

Author Comment

by:andrewl77
ID: 17783726
This is what my code looks like at present:  What change would make this happen.

    Dim conn As ADODB.Connection
    Set conn = New ADODB.Connection
   
    conn.CursorLocation = adUseClient
    conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
        & "DSN=1234;database=umas;uid=12343;pwd=1234
    conn.Open
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
   
    rs.Open "select * from umpire where 1 = 0", conn, adOpenDynamic, adLockOptimistic
   
    rs.addnew
   
    rs!firstname = firstname
    If Me.middlename = "" Then
   
    Else
    rs!middlename = middlename
    End If
    rs!surname = surname
   
    rs.update
    Set rs = Nothing
   
    frmumpiredetails.umplist.Clear
   
    Dim rs1 As ADODB.Recordset
    Set rs1 = New ADODB.Recordset
   
    rs1.Open "select * from umpire where active = 0 order by surname", conn, adOpenDynamic, adLockOptimistic
   
    Set frmumpiredetails.umplist.DataSource = rs1
    Do Until rs1.EOF
    frmumpiredetails.umplist.AddItem rs1!surname & " " & rs1!firstname
    frmumpiredetails.umplist.ItemData(frmumpiredetails.umplist.NewIndex) = rs1!umpireno
    rs1.MoveNext
   
    Loop
   
    rs1.Close
         
    conn.Close
    Set conn = Nothing
   
    Unload frmumpnew
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17783797
The simplest way to add the new item without clearing the list.

...
    End If
    rs!surname = surname
    rs.Update
   
   
    frmumpiredetails.umplist.AddItem surname & " " & firstname
    frmumpiredetails.umplist.ItemData(frmumpiredetails.umplist.NewIndex) = rs.umpireno
    Set rs = Nothing

    conn.Close
    Set conn = Nothing
   
    Unload frmumpnew
       
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:andrewl77
ID: 17783803
How do i then sort the list by surname?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17783937
If the Sorted property of the ListBox is set to True (at design time), it will sort automatically.
0
 

Author Comment

by:andrewl77
ID: 17786254
Okay...now back to the actual question once all that is done, how do i go to the record i just added on the other form?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 50 total points
ID: 17787524
Sorry. I missed that bit off the last lot of code.

   frmumpiredetails.umplist.ListIndex=frmumpiredetails.umplist.NewIndex
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question