The code displays only the first record.but???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vbbeginner07
    New Member
    • Dec 2007
    • 103

    The code displays only the first record.but???

    The follwing code is of a listview where i have to a to display the id and the name from a particular table ,empdetail.

    This is in the second form,dispalying id and name
    [code=vb]
    Private Sub Form_Load()
    ListView1.View = lvwReport
    ListView1.Colum nHeaders.Add , , "NAME"
    ListView1.Colum nHeaders.Add , , "ID"
    ListView1.Refre sh
    rs.Open "select * from empdetail", conn, adOpenStatic, adLockOptimisti c
    While Not rs.EOF
    ListView1.Refre sh
    With ListView1
    Set lvitem = ListView1.ListI tems.Add(, , rs!Name)
    lvitem.SubItems (1) = rs!id
    End With
    rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    LVFullRowSelect ListView1
    Form2.txtgros.E nabled = False
    Form2.txtnsal.E nabled = False
    Form2.txtoh.Ena bled = False
    Form2.txtotamt. Enabled = False
    Form2.txtotrt.E nabled = False
    Form2.txtrate.E nabled = False
    Form2.txttr.Ena bled = False
    dtpay.Value = Date
    End Sub[/code]

    The following is in first form,adding new record to the database
    [code=vb]
    Private Sub cmdAdd_Click()
    txtid.Enabled = True
    If Form1.txtid.Tex t = " " Then
    MsgBox "Enter the id,Please!!!", vbOKOnly, "PAYROLL"
    txtid.SetFocus
    With txtid
    .SelStart = 0
    '.SelLength = Len(txtid.Text)
    .SetFocus
    End With
    Exit Sub
    ElseIf txtname.Text = " " Then
    MsgBox "Enter the name,Please!!!" , vbOKOnly, "PAYROLL"
    'txtname.SetFoc us
    Exit Sub
    With txtname
    .SelStart = 0
    '.SelLength = Len(txtname.Tex t)
    .SetFocus
    End With
    'End If
    ElseIf txtwhr.Text = " " Then
    MsgBox "Enter the working hours,Please!!! ", vbOKOnly, "PAYROLL"
    'txtwhr.SetFocu s
    Exit Sub
    With txtwhr
    .SelStart = 0
    '.SelLength = Len(txtwhr.Text )
    .SetFocus
    End With
    'End If
    ElseIf txtrate.Text = " " Then
    MsgBox "Enter the rate,Please!!!" , vbOKOnly, "PAYROLL"
    txtrate.SetFocu s
    Exit Sub
    With txtrate
    .SelStart = 0
    '.SelLength = Len(txtrate.Tex t)
    .SetFocus
    End With
    ''End If
    ElseIf txtorate.Text = " " Then
    MsgBox "Enter the Overtime Rate,Please!!!" , vbOKOnly, "PAYROLL"
    'txtorate.SetFo cus
    'txtname.SetFoc us
    Exit Sub
    With txtorate
    .SelStart = 0
    '.SelLength = Len(txtname.Tex t)
    .SetFocus
    End With
    'End If
    'End If
    Else
    rs.Open "select * from empdetail Where ID='" & txtid.Text & "'", conn, adOpenStatic, adLockOptimisti c
    If rs.EOF Then
    conn.Execute "insert into empdetail(id,na me,whours,rate, otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
    MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
    Else
    'ID Found In DB (Duplicate)
    MsgBox "Duplicate Entry"
    End If
    'End If
    rs.Close
    Set rs = Nothing
    ListView1.ListI tems.Clear
    addcol
    Form1.txtid.Tex t = " "
    Form1.txtname.T ext = " "
    Form1.txtwhr.Te xt = " "
    Form1.txtrate.T ext = " "
    Form1.txtorate. Text = " "
    End If
    End Sub[/code]

    Please check the code!!!
    Last edited by debasisdas; Feb 6 '08, 05:43 AM. Reason: added code=vb tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Please find a related article here .

    Comment

    Working...