Results 1 to 4 of 4

Thread: Blank Form & Primary Key in Access ...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    Decatur, AL US
    Posts
    14

    Post

    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 ....


  2. #2
    Lively Member
    Join Date
    Jan 1999
    Posts
    82

    Post

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    Decatur, AL US
    Posts
    14

    Post

    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.

  4. #4
    Lively Member
    Join Date
    Jan 1999
    Posts
    82

    Post

    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
  •  



Click Here to Expand Forum to Full Width