Solved

Adding New Record

Posted on 2006-10-22
7
133 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:andrewl77
Comment Utility
How do i then sort the list by surname?
0
 
LVL 76

Expert Comment

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

Author Comment

by:andrewl77
Comment Utility
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
Comment Utility
Sorry. I missed that bit off the last lot of code.

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now