Results 1 to 2 of 2

Thread: hello serge .

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2000
    Location
    india
    Posts
    39

    Thumbs up

    hi serge.
    i know there is a small error it is howing no current record.
    help me what to do?

    empname and empid.
    priya 1
    priya 2
    reya 4
    ani 8
    priya 2

    form2 contains textbox and listbox.
    if i entered priya in the textbox,corresponding empid should be listed in the listbox.
    say
    1
    2
    2
    if reya means
    4.

    i tried below it is showing no current record?

    Private Sub cmd_list_Click()
    Dim E As String
    Dim I As Integer
    Set WS = DBEngine.Workspaces(0)
    Set DB = WS.OpenDatabase("C:\WINDOWS\PATS.MDB")
    Set RS = DB.OpenRecordset("EMP", dbOpenDynaset)
    E = "select empid FROM EMP WHERE ENAME='" & Text1.Text & "'"
    Set rsl = DB.OpenRecordset(E, dbOpenDynaset)
    rsl.MoveLast
    I = rsl.RecordCount
    If I > 1 Then
    rsl.MoveFirst
    Do While Not rsl.EOF
    List1.List(j) = rsl.Fields("EMPID").Value
    rsl.MoveNext
    Loop
    End If
    ppr

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    I dont understand why you're searching for the ID when you can load ID along with the EmpName into the ListBox.
    Code:
    Dim db As Database
    Dim rs As Recordset
    
    Set db = Workspaces(0).OpenDatabase("C:\MyDB.mdb")
    Set rs = db.OpenRecordset("Select * From EMP", dbOpenSnapshot)
    
    Do Until rs.EOF
        List1.AddItem rs.Fields("EmpName").Value
        List1.ItemData(List1.NewIndex) = rs.Fields("EmpId").Value
        rs.MoveNext
    Loop
    Then when you need to find out the ID of the selected Item, you can do something like this:
    Code:
    Private Sub List1_Click()
        With List1
            MsgBox "ID of employee " & .List(.ListIndex) & " is " & .ItemData(.ListIndex)
        End With
    End Sub

    Regards,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width