please write the code inside the code tags always . it is much readable.
Code:
Private Sub cmdsave_Click()
connectDB
rs.Open "Select*from accreg", db, 3, 3
rs.Open "Select*from accreg where AccNo=" & txtAccNo.Text, db, 3, 3
If txtAccNo.Text <> ListView1.ListItems.Add.SubItems(1) = 0 Then
'for you to check in the entire list you have add a for loop
Dim i%
For i = 1 To ListView1.ListItems.Count
If txtAccNo.Text = ListView1.ListItems(i).SubItems(1) Then
MsgBox "AccNo already exists", vbOKOnly
Else
clearall 'all text boxes
End If
Next
Else
rs.AddNew
rs(1) = txtAccNo
rs(2) = txttitle
rs(3) = txtauthor
rs.Update
End If
Set rs = Nothing
db.Close: Set db = Nothing
MsgBox "Successfully added new record", vbInformation, "SAVE"
txtAccNo = Empty
txttitle = Empty
txtauthor = Empty
txtAccNo.SetFocus
LoadData 'To refresh record
End Sub
Private Sub cmdsearch_Click()
ListView1.ListItems.Clear
Dim list As ListItem
Dim x As Integer
connectDB
rs.Open "Select*from accreg where AccNo=" & txtsearch.Text, db, 3, 3
'rs.Open "Select * from accreg where Title like='" & txtsearch.Text, db, 3, 3
Do Until rs.EOF
Set list = ListView1.ListItems.Add(, , rs(0))
For x = 1 To 3 'number of fields in the date base minus one
list.SubItems(x) = rs(x)
Next x
rs.MoveNext
Loop
Set rs = Nothing
db.Close: Set db = Nothing
End Sub
Private Sub Form_Load()
With ListView1.ColumnHeaders
.Add , , "ID", 0
.Add , , "AccNo", 1000
.Add , , "Title", 3000
.Add , , "Author", 2500
End With
LoadData
End Sub
Sub LoadData()
ListView1.ListItems.Clear
Dim list As ListItem
Dim x As Integer
connectDB
rs.Open "Select*from accreg", db, 3, 3
Do Until rs.EOF
Set list = ListView1.ListItems.Add(, , rs(0))
For x = 1 To 3 'number of fields in the date base minus one
list.SubItems(x) = rs(x)
Next x
rs.MoveNext
Loop
Set rs = Nothing
db.Close: Set db = Nothing
End Sub
in the above code the following code is not working
rs.Open "Select*from accreg where AccNo=" & txtAccNo.Text, db, 3, 3
If txtAccNo.Text <> ListView1.ListItems.Add.SubItems(1) = 0 Then
'for you to check in the entire list you have add a for loop
Dim i%
For i = 1 To ListView1.ListItems.Count
If txtAccNo.Text = ListView1.ListItems(i).SubItems(1) Then
MsgBox "AccNo already exists", vbOKOnly
Else
clearall 'all text boxes
End If
Next
Else