i am writing a library program with visual basic and i have the following problem.
first of all all the book titles, author, publisher and category are stored in an access database, all in the same table.
i am using ADO to access and to store info in the database.
the problem is that i dont want the user to be able to enter the same info twice.
so when the user press the save button i want to check in my database that the fields title,author,publisher and category are not the same as the one the user enters.
i tried this code but not seem to work:
Private Sub save_Click()
If Text1.Text = "" Then
MsgBox ("You must fill the Title field!")
ElseIf Text2.Text = "" Then
MsgBox ("You must fill the Author field!")
ElseIf Text3.Text = "" Then
MsgBox ("You must fill the Publisher field!")
ElseIf Text4.Text = "" Then
MsgBox ("You must fill the Category field!")
Else
Do Until Adodc1.Recordset.EOF
If Adodc1.Recordset.Fields("Title") = (Text1.Text) And _
Adodc1.Recordset.Fields("Author") = (Text2.Text) And _
Adodc1.Recordset.Fields("Publisher") = (Text3.Text) And _
Adodc1.Recordset.Fields("Category") = (Text4.Text) Then
MsgBox ("Record already exists.Can not have duplicate records!")
MsgBox ("Record not saved")
Adodc1.Recordset.MovePrevious
Exit Do
Else
Adodc1.Recordset.Fields("Title") = Text1.Text
Adodc1.Recordset.Fields("Author") = Text2.Text
Adodc1.Recordset.Fields("Publisher") = Text3.Text
Adodc1.Recordset.Fields("Category") = Text4.Text
Adodc1.Recordset.Update
MsgBox "Book Saved", vbInformation, "INFORMATION"
End If
' Adodc1.Recordset.MoveNext
'
Loop
End If
please help
first of all all the book titles, author, publisher and category are stored in an access database, all in the same table.
i am using ADO to access and to store info in the database.
the problem is that i dont want the user to be able to enter the same info twice.
so when the user press the save button i want to check in my database that the fields title,author,publisher and category are not the same as the one the user enters.
i tried this code but not seem to work:
Private Sub save_Click()
If Text1.Text = "" Then
MsgBox ("You must fill the Title field!")
ElseIf Text2.Text = "" Then
MsgBox ("You must fill the Author field!")
ElseIf Text3.Text = "" Then
MsgBox ("You must fill the Publisher field!")
ElseIf Text4.Text = "" Then
MsgBox ("You must fill the Category field!")
Else
Do Until Adodc1.Recordset.EOF
If Adodc1.Recordset.Fields("Title") = (Text1.Text) And _
Adodc1.Recordset.Fields("Author") = (Text2.Text) And _
Adodc1.Recordset.Fields("Publisher") = (Text3.Text) And _
Adodc1.Recordset.Fields("Category") = (Text4.Text) Then
MsgBox ("Record already exists.Can not have duplicate records!")
MsgBox ("Record not saved")
Adodc1.Recordset.MovePrevious
Exit Do
Else
Adodc1.Recordset.Fields("Title") = Text1.Text
Adodc1.Recordset.Fields("Author") = Text2.Text
Adodc1.Recordset.Fields("Publisher") = Text3.Text
Adodc1.Recordset.Fields("Category") = Text4.Text
Adodc1.Recordset.Update
MsgBox "Book Saved", vbInformation, "INFORMATION"
End If
' Adodc1.Recordset.MoveNext
'
Loop
End If
please help