PDA

Click to See Complete Forum and Search --> : delete emply record on form load


Bebe
Mar 16th, 2000, 09:32 PM
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?

Serge
Mar 17th, 2000, 03:46 AM
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:


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

Mildumar
Mar 21st, 2000, 02:47 AM
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.