Delete Record (subform involved) Access 97

  • Thread starter Thread starter PBrown
  • Start date Start date
P

PBrown

Currently the form is set up to open on a new record.
However, even if the user does not enter any information
it is saved. This is causing excessive blank records. I
believe the problem may lie with the fact that the subform
has default values (0) in the 5 value fields and when the
form is opened the 0's are filled in which causes the
record to save. I have tried taking out the default of 0
from the table for the subform, but it causes errors when
running the reports due to some of the calculations.
Basically because not all 5 fields have to be used every
time and the report can not multiple/add/divide by null.

Is there away to have the button "Return to Main" (Which
closes the form and opens the main form) to also state
something like (I know the code is incorrect, but is
basically says what is needed):

If isnull [description] then
Do not save record
else
save record
end if

Where [description] is a field from the subform named: Car
Data, and the subforms control source is Car subform

Thank you in advance for any and all help, this is
begining to bug me.... Too many excessive records slowing
down the reports.

Thank you again,

PBrown
 
Response is at bottom.
Currently the form is set up to open on a new record.
However, even if the user does not enter any information
it is saved. This is causing excessive blank records. I
believe the problem may lie with the fact that the subform
has default values (0) in the 5 value fields and when the
form is opened the 0's are filled in which causes the
record to save. I have tried taking out the default of 0
from the table for the subform, but it causes errors when
running the reports due to some of the calculations.
Basically because not all 5 fields have to be used every
time and the report can not multiple/add/divide by null.

Is there away to have the button "Return to Main" (Which
closes the form and opens the main form) to also state
something like (I know the code is incorrect, but is
basically says what is needed):

If isnull [description] then
Do not save record
else
save record
end if

Where [description] is a field from the subform named: Car
Data, and the subforms control source is Car subform

Default values will not create a new record on their own. They merely provide a
default value when the record is "dirtied" (when you start to create a new
record by entering/selecting a value). It is possible, however, that your form
has code in the form's "On Load", "On Open" or "On Current" event procedure that
is changing or setting a value when the form is first opened (or moves to a new
record) or a value is set in the new record by code opening the form from within
a calling form.

You *can* implement code in the form's "BeforeUpdate" event procedure to check
for valid entries, as you have suggested, and when vital values are missing (you
would want to check several fields to ensure that the user hadn't simply
forgotten to enter a value in one of the fields) you can undo the record using
the Undo method of the form:

'************EXAMPLE START
'If there is no values in either field1 or field2 AND
' there is no value in field3 then do not save record
' (the "+" between fields 1 and 2 cause a null value to
' be returned if either field 1 OR 2 contains a null)
If Len(([Field1]+[Field2]) & [Field3] & vbNullString) = 0 Then
Me.Undo
End If
'************EXAMPLE END

The only problem with this *might* occur when and if all of the vital fields
have default values set and, thus, would not be empty when your code checks for
missing values. If your new record is being generated from within code in
another form, you might want to consider moving the code that sets the value out
of the calling form and into the "BeforeInsert" event procedure of the called
form to prevent a new record from being started until the user actually makes an
edit to the form.
 
Back
Top