Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Record Message Not Wanted 1

Status
Not open for further replies.

chrisaroundtown

Technical User
Jan 9, 2003
122
0
0
AU
Hi,

I have users filling in a form for orders. If a user gets halfway through the form then decides not to continue for whatever reason I don't want the entry to save in the table. I have added a Clear button which will delete the current record, this presents two problems:

1) After pressing the clear button a message box comes up saying "You are about to delete 1 record........continue" clicking Yes deletes the record. I don't want to give users this choice, is there a way to delete without the message box.

2) I don't want the users to be able to save a record that is only half completed. Is there a way to stop this at all?

Thanks
Chris
 
I know this isn't very specific, but there are generally registry keys that can hold the options such as taking away the option you listed in your first problem. As for the second, maybe a loop that goes through the latest record at the OnClose event, and if any fields are missing, the record will automatically delete. Again, you will run into the "Continue with delete?" option, but there should be a registry edit to prevent that option.

Hope this helps.

Jon
 
Thanks Jon,

Do you where I would find these registry keys? I can't seam to find anything in help about them.

Also, what code would you use to create a loop?

Thanks
Chris
 
Let me get back to you on this tomorrow. I am tired, and have to get some sleep, but I will try and find the registry key for you, and write a loop, and get that to you tomorrow. Sorry for the delay.

Jon
 
Thanks Jon for all your help, can't wait until tomorrow.

Thanks
Chris
 
I don't think you need bother with registry keys ...

Turn confirmation messages on or off
You can turn confirmation messages on or off for record changes, document deletions, or, in Microsoft Access databases, action queries.

On the Tools menu, click Options.


Click the Edit/Find tab.


Under Confirm, select or clear the appropriate check boxes.


Transcend
[gorgeous]
 
Thanks Transend,

That fixes the first problem, any idea on how I can display a message box on hitting the save button to say which fields are empty and prompt the user to fill them in?

Thanks
Chris
 
Yep,

on the click even of your save button, put in a check.

If txtText.text = "" then
msgbox "Not all fields have values, cannot save"

else
'call or put your save code here
end if

Transcend
[gorgeous]
 
Thanks Transcend,

Below is my code as it is with your help. If all fields are filled in I get a message saying "Run Time Error 2046, The command or action 'Save Record' isn't available now".

Any idea why?

Thanks
Chris

Private Sub Savebtn_Click()

cmbProgram.SetFocus
If cmbProgram.Text = "" Then
MsgBox "Please select Program", vbOKOnly, "Program?"
Else
txtMemberName.SetFocus
If txtMemberName.Text = "" Then
MsgBox "Please enter Member Name", vbOKOnly + vbCritical, "Member Name?"
Else
txtCardNo.SetFocus
If txtCardNo.Text = "" Then
MsgBox "Please enter Card Number", vbOKOnly + vbCritical, "Card No?"
Else
txtOrderDate.SetFocus
If txtOrderDate.Text = "" Then
MsgBox "Please enter Order Date", vbOKOnly + vbCritical, "Order Date?"
Else
txtOrderNo.SetFocus
If txtOrderNo.Text = "" Then
MsgBox "Please enter Order Number", vbOKOnly + vbCritical, "Order No?"
Else
cmbAwardCode.SetFocus
If cmbAwardCode.Text = "" Then
MsgBox "Please select Award Code", vbOKOnly + vbCritical, "Award Code"
Else
cmbProduct.SetFocus
If cmbProduct.Text = "" Then
MsgBox "Please select Product", vbOKOnly + vbCritical, "Product?"
Else
cmbSupplier.SetFocus
If cmbSupplier.Text = "" Then
MsgBox "Please select Supplier", vbOKOnly + vbCritical, "Supplier?"
Else
txtIssue.SetFocus
If txtIssue.Text = "" Then
MsgBox "Please describe Issue", vbOKOnly + vbCritical, "Issue?"
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acNewRec
End If
End If
End If
End If
End If
End If
End If
End If
End If

End Sub
 
I would like to throw in another option in the first question.

Use

DoCmd.Setwarnings False 'This turns off the warnings
DoCmd.RunCommand accmdselectrecord
DoCmd.RunCommand accmddeleterecord
DoCmd.Setwarnings True 'This turns warnings back on

I use this method because there are times when I want the warnings to display and this gives me greater control.

Let me pose another question in the code above.

What if the user hits a pageup or pagedown to go to the next record. They have just bypassed your 'button'. If there are required fields you may want to mark them as required in the table design and then catch the error on the form if the record tries to save without all of the required data. That way a message can be displayed and you can cancel the error giving users a chance to enter the 'rest' of the data.
Tim
 
If you use the following line of code, there will not be a notification message, even if you turn them on.

CurrentDb.Execute "DELETE * FROM TblName WHERE Conditions"

Sorry I couldn't help you out more last night.

Hope this helps you.

Jon
 
I assume you are getting the error at the line
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord?

I'm not really sure whats happening, is your menu item enabled? Sorry I have a cold .. heads all blurred .. i'll think on it

Transcend
[gorgeous]
 
Hi jsaliers,
I've used your Idea and it works, Thanx, A * 4 U
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top