For anyone that might have a similar problem: I was able to get around changing the close event for the datasheet view of the query by automatically creating a datasheet form, and then using the onclose event. My code follows.
DoCmd.OpenQuery "QueryName"
DoCmd.RunCommand acCmdNewObjectAutoForm
DoCmd.Close acQuery, "QueryName"
DoCmd.RunCommand acCmdDatasheetView
'The following is so that the user is not prompted to save the form
DoCmd.Save acForm, "Form1"
Forms("Form1").OnClose = "=DetermineIfSave()"
Function DetermineIfSave()
SaveQuery = MsgBox("Would you like to save this query?", vbYesNo)
If SaveQuery = vbYes Then
queryname = InputBox("Enter the name you would like for the query:", , "DefaultName")
'The following If...Then statement is incase the user pushes 'Cancel'
If queryname = "" Then
DoCmd.DeleteObject acQuery, "QueryName"
DoCmd.OpenForm "DeleteForm"
Exit Function
End If
DoCmd.Rename queryname, acQuery, "newQuery"
Else: DoCmd.DeleteObject acQuery, "newQuery"
End If
DoCmd.OpenForm "DeleteForm"
End Function
The form 'DeleteForm' was to delete the form that was automaticall created. If you were to try and put: 'DoCmd.DeleteObject acForm, "Form1"' into the OnClose Event then you would get an error message that says you can't delete a form while it is open. Therefore, I created another form with a command button the user must push that would delete the form.
