1-Button Click to erase form...

C

Charles Waters

I was wondering if there is a way to have a button on my form, that
would wipe out the contents of the record all in one shot?

Something that would wipe out all the data entered manually into the
fields, or "said fields", as well as erasing the data from the
subform, adjoined to that record?

Is this at all possible?
 
J

John W. Vinson

I was wondering if there is a way to have a button on my form, that
would wipe out the contents of the record all in one shot?

Something that would wipe out all the data entered manually into the
fields, or "said fields", as well as erasing the data from the
subform, adjoined to that record?

Is this at all possible?

On a single form, yes:

Private Sub cmdBlankItAll_Click()
Me.Undo
End Sub

With a subform... MUCH harder. The problem is that the instant you set focus
to any subform control, the main form record is written to disk. It can no
longer be undone. On the Subform, whenever you move to another record, or back
to the main form, that subform record is written to disk. It's already SAVED -
you can't easily decide "oh I didn't mean it".

What you will need to do is execute a Delete query to delete the mainform
record; if you have Cascade Deletes set on the relationship between the two
tables this will delete the child records. If not, you'll need two delete
queries, one for the subform's table, one for the mainform.

The dilemma is that in a multiuser system you can't be sure that some OTHER
user hasn't made use of the data already written to disk.

John W. Vinson [MVP]
 
C

Charles Waters

On a single form, yes:

Private Sub cmdBlankItAll_Click()
Me.Undo
End Sub

With a subform... MUCH harder. The problem is that the instant you set focus
to any subform control, the main form record is written to disk. It can no
longer be undone. On the Subform, whenever you move to another record, or back
to the main form, that subform record is written to disk. It's already SAVED -
you can't easily decide "oh I didn't mean it".

What you will need to do is execute a Delete query to delete the mainform
record; if you have Cascade Deletes set on the relationship between the two
tables this will delete the child records. If not, you'll need two delete
queries, one for the subform's table, one for the mainform.

The dilemma is that in a multiuser system you can't be sure that some OTHER
user hasn't made use of the data already written to disk.

             John W. Vinson [MVP]

John...

Thank you for the reply, sir... I am going to be taking the SubForm
that was made, and migrating it over as part of the mainform that I am
working on. Why in the world it was setup in the 1st place as a
SubForm, I haven't the slightest idea...

Once that is done, then the command you gave me will work for the
whole thing, correct!?
 
J

John W. Vinson

Thank you for the reply, sir... I am going to be taking the SubForm
that was made, and migrating it over as part of the mainform that I am
working on. Why in the world it was setup in the 1st place as a
SubForm, I haven't the slightest idea...

Once that is done, then the command you gave me will work for the
whole thing, correct!?

What's the Recordsource? Are you updating one single table (just using a
subform to do so, which I agree would be peculiar), or two tables in a one to
many relationship?

If it's one table on a single form, then the Me.Undo line is all that you
need.

John W. Vinson [MVP]
 
C

Charles Waters

What's the Recordsource? Are you updating one single table (just using a
subform to do so, which I agree would be peculiar), or two tables in a oneto
many relationship?

If it's one table on a single form, then the Me.Undo line is all that you
need.

             John W. Vinson [MVP]

You know, I don't honestly really know how the last idiot wrote the
form as far as the subform goes. I am going to modify it today and
figure it out, so we'll see what happens. I'll let you know...
 
C

Charles Waters

On a single form, yes:

Private Sub cmdBlankItAll_Click()
Me.Undo
End Sub

With a subform... MUCH harder. The problem is that the instant you set focus
to any subform control, the main form record is written to disk. It can no
longer be undone. On the Subform, whenever you move to another record, or back
to the main form, that subform record is written to disk. It's already SAVED -
you can't easily decide "oh I didn't mean it".

What you will need to do is execute a Delete query to delete the mainform
record; if you have Cascade Deletes set on the relationship between the two
tables this will delete the child records. If not, you'll need two delete
queries, one for the subform's table, one for the mainform.

The dilemma is that in a multiuser system you can't be sure that some OTHER
user hasn't made use of the data already written to disk.

             John W. Vinson [MVP]

John...

I tried running your version of the undo, as well as the MS version
of undo, and nothing. With MS's version, I get "Cannot Undo Record" or
whatever the error message is.. With yours, I get nothing...

The problem is, the record entry is already there. It already
exists, and so nothing is being typed in right now, at this time.

The MS version of Delete Record is more of what I am looking for,
although the only problem, is it actally erases the whole entire
record entry from the table. What I need to do, is just goto 4 or 5
boxes in that record and erase the information I see when I pull up
that specific record.

It seems to look like what I am looking for just can't be done,
which is fine if that's the case...
 
J

John W. Vinson

I tried running your version of the undo, as well as the MS version
of undo, and nothing. With MS's version, I get "Cannot Undo Record" or
whatever the error message is.. With yours, I get nothing...

The problem is, the record entry is already there. It already
exists, and so nothing is being typed in right now, at this time.

The MS version of Delete Record is more of what I am looking for,
although the only problem, is it actally erases the whole entire
record entry from the table. What I need to do, is just goto 4 or 5
boxes in that record and erase the information I see when I pull up
that specific record.

It seems to look like what I am looking for just can't be done,
which is fine if that's the case...

I'm quite sure that it can be done... but now I don't understand what it IS
that you want done.

"Erase form" could mean just moving to the new record. It could mean
cancelling a new record after it's been started but before it's written to
disk. It could mean deleting an existing record. Now it sounds like none of
these apply, but that you want to erase *part* of an existing record.

All of these can be done - but if we're advising you how to do one of these
things and you actually want to do a different one you'll be disappointed!

What's the *real life* situation? What do you have in the database now, and
what do you want it changed to?

John W. Vinson [MVP]
 
Top