Solved

Adding New Record

Posted on 2006-10-22
7
135 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now