Results 1 to 3 of 3

Thread: delete emply record on form load

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    Would anyone know the code ( i am using access 97) to check the database for an empty record when the program loads and delte any empty records in the database.

    for example in my program if someones computer happens to freeze in the midst of doing an add new a blank record would be added to the database so i was thinking that if this happens i could resolve it by having the program look through the database and delete any empty records.

    any ideas on this?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    The best way is to restrict the user of adding an empty record.
    But if you still want to delete an empty record, then you can do something like this. Add a reference to Microsoft ActiveX library 2.1 (or select the highest version you have installed), then use the code like this:

    Code:
    Dim cn As New ADODB.Connection
    
    cn.Provider = "Microsoft.Jet.OLEDB.3.51"
    cn.Open "C:\MyDB.mdb", "admin", ""
    cn.Execute "Delete MyTable Where (Field1 Is Null And Field2 Is Null) Or (Field1 = "" And Field2 = "")
    Assuming that:
    C:\MyDB.mdb is my database.

    MyTable is a table in the database

    Field1 and Field2 are two fields in the MyTable


  3. #3
    New Member
    Join Date
    Jan 1999
    Location
    Shawnee Mission, KS
    Posts
    14
    It would be better to build your form with unbound controls and then only post them when each control has the data required.

    Or run a delete query each time the form is loaded and remove those records that incomplete.

    Hope this helps.

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