auto deleting records that are missing data

P

PS

Access 03 / I have a MAIN FORM and a "subform" that is accessed when you
select the checkbox on the main form. Code is used to automately fill in the
CASE NO on the subform when it opens.
Heres the problem; when an operator accidently checks the box and opens the
subform, a new record is now created in the subform BUT now realizing the
mistake, the operator closed the subform and now this leaves a record with
the CASE NO and no other data entered BUT is unfortunatly counted in the
record count.
I want to have a code or something that will automately delete these records.
 
D

David H

Have you thought about shifting the code that assigns the CASE NO to the
BEFORE INSERT event on the subform? This will keep the case number from being
assigned until the person actually starts entering information in the subform.
 
P

PS

this is code written on DUI (subform) on CASE NUMBER field

Private Sub CASENUMBER_BeforeUpdate(Cancel As Integer)
Dim strCASENUMBER As String
Dim strCriteria As String
Dim intResponse As Integer

strCASENUMBER = Me.CASENUMBER.Value
strCriteria = "[CASENUMBER]='" & strCASENUMBER & "'"


End Sub

Private Sub Form_Current()
If Me.NewRecord Then
If Not IsNull(Me.OpenArgs) Then
Me.CASENUMBER = Me.OpenArgs
End If
End If
End Sub

what do I change and how and where (need to be walked through, sorry)
 
D

David H

See my inline comments

PS said:
this is code written on DUI (subform) on CASE NUMBER field

Private Sub CASENUMBER_BeforeUpdate(Cancel As Integer)
Dim strCASENUMBER As String
Dim strCriteria As String
Dim intResponse As Integer

strCASENUMBER = Me.CASENUMBER.Value
strCriteria = "[CASENUMBER]='" & strCASENUMBER & "'"


End Sub

The sub effectively doesn't do any thing. Is there additional code that you
omitted in the post?
Private Sub Form_Current()
If Me.NewRecord Then
If Not IsNull(Me.OpenArgs) Then
Me.CASENUMBER = Me.OpenArgs
End If
End If
End Sub

If you have a CASE NUMBER field on the main form, I would delete this sub
and then change the DEFAULT VALUE of the CASE NUMBER field on the SUB form to
reference the value on the main form as in
=[Forms]![(mainFormName)]![(fieldName)]
When the subform opens, it will show a "new" record with the CASE NUMBER
field set to the value of the main form, however the record will not actually
be inserted into the underlying table until the user enters information in
the other fields. The "new" record isn't a "new" record per se.
 
P

PS

David, here is more infromation about the database:
MAIN FORM primary key = CASENUMBER
DUI FORM primary key = AUTONUMBER
RELATIONSHIP = CASENUMBER to CASENUMBER
noticed one thing, in the DUI TABLE the CASENUMBER is INDEXED =
Yes(Duplicates ok)
I beleive I was assuming that if I had Yes(No Duplicates), the code that
"duplicates the CASENUMBER and inserts it auto into the DUI CASENUMBER field
would not work because that would be a "duplicate"
Be advised, there are 200 records already entered in the DUI TABLE
would not want to do anything that would adversly effect the data at this
point

David H said:
See my inline comments

PS said:
this is code written on DUI (subform) on CASE NUMBER field

Private Sub CASENUMBER_BeforeUpdate(Cancel As Integer)
Dim strCASENUMBER As String
Dim strCriteria As String
Dim intResponse As Integer

strCASENUMBER = Me.CASENUMBER.Value
strCriteria = "[CASENUMBER]='" & strCASENUMBER & "'"


End Sub

The sub effectively doesn't do any thing. Is there additional code that you
omitted in the post?
Private Sub Form_Current()
If Me.NewRecord Then
If Not IsNull(Me.OpenArgs) Then
Me.CASENUMBER = Me.OpenArgs
End If
End If
End Sub

If you have a CASE NUMBER field on the main form, I would delete this sub
and then change the DEFAULT VALUE of the CASE NUMBER field on the SUB form to
reference the value on the main form as in
=[Forms]![(mainFormName)]![(fieldName)]
When the subform opens, it will show a "new" record with the CASE NUMBER
field set to the value of the main form, however the record will not actually
be inserted into the underlying table until the user enters information in
the other fields. The "new" record isn't a "new" record per se.
what do I change and how and where (need to be walked through, sorry)
 
D

David H

Comment out the Form_Current code and add the Default Value to the CASE
NUMBER control that I indicated in my prior post. This will *only* impact new
records added. The code in the Form_Current code only fires if you're on a
New Record anyways. From a design standpoint, the code should actually be
under the Form_BeforeInsert event.

PS said:
David, here is more infromation about the database:
MAIN FORM primary key = CASENUMBER
DUI FORM primary key = AUTONUMBER
RELATIONSHIP = CASENUMBER to CASENUMBER
noticed one thing, in the DUI TABLE the CASENUMBER is INDEXED =
Yes(Duplicates ok)
I beleive I was assuming that if I had Yes(No Duplicates), the code that
"duplicates the CASENUMBER and inserts it auto into the DUI CASENUMBER field
would not work because that would be a "duplicate"
Be advised, there are 200 records already entered in the DUI TABLE
would not want to do anything that would adversly effect the data at this
point

David H said:
See my inline comments

PS said:
this is code written on DUI (subform) on CASE NUMBER field

Private Sub CASENUMBER_BeforeUpdate(Cancel As Integer)
Dim strCASENUMBER As String
Dim strCriteria As String
Dim intResponse As Integer

strCASENUMBER = Me.CASENUMBER.Value
strCriteria = "[CASENUMBER]='" & strCASENUMBER & "'"


End Sub

The sub effectively doesn't do any thing. Is there additional code that you
omitted in the post?
Private Sub Form_Current()
If Me.NewRecord Then
If Not IsNull(Me.OpenArgs) Then
Me.CASENUMBER = Me.OpenArgs
End If
End If
End Sub

If you have a CASE NUMBER field on the main form, I would delete this sub
and then change the DEFAULT VALUE of the CASE NUMBER field on the SUB form to
reference the value on the main form as in
=[Forms]![(mainFormName)]![(fieldName)]
When the subform opens, it will show a "new" record with the CASE NUMBER
field set to the value of the main form, however the record will not actually
be inserted into the underlying table until the user enters information in
the other fields. The "new" record isn't a "new" record per se.
what do I change and how and where (need to be walked through, sorry)

:

Have you thought about shifting the code that assigns the CASE NO to the
BEFORE INSERT event on the subform? This will keep the case number from being
assigned until the person actually starts entering information in the subform.

:

Access 03 / I have a MAIN FORM and a "subform" that is accessed when you
select the checkbox on the main form. Code is used to automately fill in the
CASE NO on the subform when it opens.
Heres the problem; when an operator accidently checks the box and opens the
subform, a new record is now created in the subform BUT now realizing the
mistake, the operator closed the subform and now this leaves a record with
the CASE NO and no other data entered BUT is unfortunatly counted in the
record count.
I want to have a code or something that will automately delete these records.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top