Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 02-01-2006, 05:12 AM   #1
Solid State Member
 
Join Date: Jun 2005
Posts: 8
Default help with ado please

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
__________________

petros is offline   Reply With Quote
Old 02-01-2006, 08:59 PM   #2
In Runtime
 
extendcradle's Avatar
 
Join Date: Jul 2005
Posts: 276
Default Re: help with ado please

what is your database? if you are using an MS Access dbase,you might just set the fields properties<indexed> <no duplicates> and then

Private Sub save_Click()
on error goto hell
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
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
'

hell:
msgbox err.description
__________________

extendcradle is offline   Reply With Quote
Old 02-02-2006, 12:46 AM   #3
Solid State Member
 
Join Date: Jun 2005
Posts: 8
Default Re: help with ado please

thanks a lot. i am using an access dbase
petros is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 09:50 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0