?
Solved

Adding New Record

Posted on 2006-10-22
7
Medium Priority
?
148 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 total points
ID: 17787524
Sorry. I missed that bit off the last lot of code.

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

840 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