Msgbox for "Nothing to Delete"

  • Thread starter rebecky via AccessMonster.com
  • Start date
R

rebecky via AccessMonster.com

Hello. I have a delete button that uses code I found here, but I want a
msgbox to say there is nothing to delete if the user is going through the
form pushing icons and the record is blank (for training purposes). It
seems so simple but I cannot figure it out.

Here is the button code,,,,,how would I have a msgbox pop up if they hit the
delete button and there is nothing to delete?

DoCmd.SetWarnings False


If MsgBox("You are About to Delete this Position. Do you really really
really want to DO this?", vbOKCancel, "TED version 2.1") = vbCancel Then
Cancel = True
MsgBox "TED has Canceled Deleting this Position :)", vbOKOnly, "TED version 2.
1"

Exit Sub

Else

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
MsgBox "The Position has been Deleted", vbOKOnly, "TED version 2.1"


End If

Exit_Command212_Click:
Exit Sub

Err_Command212_Click:
Resume Exit_Command212_Click

Thank you in advance for any ideas!!
rebecky
 
A

Allen Browne

Perhaps something like this:

If Me.Dirty Then
Me.Undo
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
ElseIf Me.NewRecord Then
MsgBox "Nothing 2 delete"
End If
 
R

rebecky via AccessMonster.com

Thanks Allen Browne! I have added part of your code to mine.....when I just
used yours the button was totally dead unless the record was blank,,,,the
only issue I have is if the user starts typing a record and then changes
his/her mind and hits the delete icon, the message box says nothing 2 delete
and I know it is because the record has not saved yet but whenever I try to
use the docmd.save on a form Access shuts down. Don't know what is up with
that, but here is what I went with. You are SO GOOD at this, do you see
anything wrong?

DoCmd.SetWarnings False

If Me.NewRecord Then
MsgBox "Record is Blank or Must be Saved to Delete. Click Save and then
Delete or use the Undo Button to Eliminate your Changes", vbOKOnly, "TED
version 2.1"
Exit Sub
End If

If MsgBox("You are About to Delete this Position. Do you really really really
want to DO this?", vbOKCancel, "TED version 2.1") = vbCancel Then
Cancel = True
MsgBox "TED has Canceled Deleting this Position :)", vbOKOnly, "TED version 2.
1"

Exit Sub
Else

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
MsgBox "The Position has been Deleted", vbOKOnly, "TED version 2.1"


End If












Allen said:
Perhaps something like this:

If Me.Dirty Then
Me.Undo
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
ElseIf Me.NewRecord Then
MsgBox "Nothing 2 delete"
End If
Hello. I have a delete button that uses code I found here, but I want a
msgbox to say there is nothing to delete if the user is going through the
[quoted text clipped - 32 lines]
Thank you in advance for any ideas!!
rebecky
 
R

rebecky via AccessMonster.com

Maybe you can help with one more thing. I have a subform within a subform
for adding multiple Job Contacts(tblsitecontacts) for each Job
(tblJobOrderInfo). The parent subform is within a Main form containing
Employer Information(tblEmployerInformation).

Some jobs have more than one contact and some employers have more than one
job order. When the contact info is the exact same for each job order an
employer has, I would like to be able to copy or carry over the previous job
order contact information......

Allen said:
Perhaps something like this:

If Me.Dirty Then
Me.Undo
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
ElseIf Me.NewRecord Then
MsgBox "Nothing 2 delete"
End If
Hello. I have a delete button that uses code I found here, but I want a
msgbox to say there is nothing to delete if the user is going through the
[quoted text clipped - 32 lines]
Thank you in advance for any ideas!!
rebecky
 
A

Allen Browne

Best to start a new thread for a new question.

The best answer will depend on what you want it to do.

Perhaps you could set the Default Value of a control in its AfterUpdate
event procedure, so it defaults to whatever was entered last. Details in:
Carry current value of a control to new records
at:
http://www.mvps.org/access/forms/frm0012.htm

Or perhaps you want to automatically insert the values from the last record
into several fields as soon as the user starts entering a new record.
Details:
Assign default values from the last record - Carry data over
at:
http://allenbrowne.com/ser-24.html
 
A

Allen Browne

Let's see if we can clarify what you need.

When the user asks to delete a record, but it's a new record that has not
even been saved yet, you don't need to delete anything. All you need to do
is undo the record, and they are back at a clean, new record again.

If they ask to delete a record that is currently being edited, Access has to
do something with the edits (either save or undo) before it can perform the
delete. The save would be a waste of effort, so it's better to undo and
delete.

So, either way, you need to undo any edits in progress.

Then, if there was an undo of the new record, you don't want to give the
user a message, because undoing it achieved what they intended. So the only
case where you want the message is where you are at a new, undirtied record.

Is that what you want? If so, go back and read the code in the previous
reply, and see if the description above matches what it does.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

rebecky via AccessMonster.com said:
Thanks Allen Browne! I have added part of your code to mine.....when I
just
used yours the button was totally dead unless the record was blank,,,,the
only issue I have is if the user starts typing a record and then changes
his/her mind and hits the delete icon, the message box says nothing 2
delete
and I know it is because the record has not saved yet but whenever I try
to
use the docmd.save on a form Access shuts down. Don't know what is up
with
that, but here is what I went with. You are SO GOOD at this, do you see
anything wrong?

DoCmd.SetWarnings False

If Me.NewRecord Then
MsgBox "Record is Blank or Must be Saved to Delete. Click Save and then
Delete or use the Undo Button to Eliminate your Changes", vbOKOnly, "TED
version 2.1"
Exit Sub
End If

If MsgBox("You are About to Delete this Position. Do you really really
really
want to DO this?", vbOKCancel, "TED version 2.1") = vbCancel Then
Cancel = True
MsgBox "TED has Canceled Deleting this Position :)", vbOKOnly, "TED
version 2.
1"

Exit Sub
Else

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
MsgBox "The Position has been Deleted", vbOKOnly, "TED version 2.1"


End If

Allen said:
Perhaps something like this:

If Me.Dirty Then
Me.Undo
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
ElseIf Me.NewRecord Then
MsgBox "Nothing 2 delete"
End If
Hello. I have a delete button that uses code I found here, but I want a
msgbox to say there is nothing to delete if the user is going through
the
[quoted text clipped - 32 lines]
Thank you in advance for any ideas!!
rebecky
 
R

rebecky via AccessMonster.com

Yes, I tried both of these solutions, and they work beautifully from one
record to the next in the ContactInfosubform. However, if the user goes to
enter a new job order in the PositionInformationsubform(SingleForm) the
ContactInfosubform(SingleForm) within the PositionInformationSubform stays
blank. For example: Joes Cafe has a job order for a waitress. This is the
position information in the subform within the Employer Information Main Form.
The contact info for this position is Joe Blow (phone, address, fax # etc.)
and goes in the ContactInfo subform within the PositionInformationSubform.
Joes Cafe is now posting an open position for Cook. The user clicks on the
add new position button in the PositionInformationSubform and adds the new
position information for Cook, but the contact info for the position of Cook
is exactly the same as the contact info for the job order Waitress and I
want that to automatically fill in within the ContactInfosubform.

Can that be done?

Thank you for your time.


Allen said:
Best to start a new thread for a new question.

The best answer will depend on what you want it to do.

Perhaps you could set the Default Value of a control in its AfterUpdate
event procedure, so it defaults to whatever was entered last. Details in:
Carry current value of a control to new records
at:
http://www.mvps.org/access/forms/frm0012.htm

Or perhaps you want to automatically insert the values from the last record
into several fields as soon as the user starts entering a new record.
Details:
Assign default values from the last record - Carry data over
at:
http://allenbrowne.com/ser-24.html
Maybe you can help with one more thing. I have a subform within a subform
for adding multiple Job Contacts(tblsitecontacts) for each Job
[quoted text clipped - 6 lines]
job
order contact information......
 
A

Allen Browne

rebecky via AccessMonster.com said:
... I want that to automatically fill in within the ContactInfosubform.

Best to start a new thread for your new question.
 

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