|
-
Jul 31st, 1999, 04:17 AM
#1
Thread Starter
New Member
I used the code that Preeti posted ...
http://www.vb-world.net/ubb/Forum3/HTML/001380.html
and it works great ... NOW the problem I am having is that if I run the form ... it puts the blank record in the database .. and if I don't add a something and just close down the form ... the next time I try to run the form it gives me an error ... because the primary key is set to no duplicates ...
Is there anyway I can post bogus data or delete the blank record ... if I don't enter any information?
HELP ....
-
Aug 1st, 1999, 05:27 PM
#2
Lively Member
Hi,
Why don't you try to put a stop so you don't write a blank or bogus data? It's not a good idea to populate a database with garbage data because then your database will become unmanageable.
However you set up to add a new record, before you add the record, make sure that the primary key field has a value:
if primaryfield <> "" then
recordset.addnew
end if
primaryfield is the textbox/combobox etc that you used on your form for the field in the database
This way, you will only add records that have data.
HTH,
Preeti
-
Aug 1st, 1999, 06:22 PM
#3
Thread Starter
New Member
Preeti,
I'm a bit confused ... I'm using the code (http://www.vb-world.net/ubb/Forum3/HTML/001380.html) to give me a blank form @ run time. Doesn't this code already write a record to the database? If so, then how can I delete this record if nothing is entered? Because if I don't delete it or write something different to it then the form want run the next time I try to run it, because of the primary key.
I'm new to VB ... so please bear with me 
ANY help is GREALTY Appreciated.
-
Aug 1st, 1999, 10:23 PM
#4
Lively Member
Hi,
What you could do, is put this code in the click event of a button. This way, a record will only get saved if the user clicks on the button.
I'm not sure how your form is set up, but from what it sounds like, when you exit the form, you automatically save a record to the database. My previous suggestion was for this such case. If you do not have any data to be saved (primary key left blank) then don't save any data. You would put this if statement before the code from the other post.
Also, if you have declared a field as a primary key, you should not be allowed to save blanks to this field. It's bad database management.
HTH,
Preeti
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|