TimKestermont
asked on
onclose event
I want to bring up a yes no confirmation dialog on close event. Then on choice to Save I don't want to close the form but run a save command button on a subform. The subform has a save button with code.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Basically, replace MyMainForm and MySubformControl with the names of your main form and the subform control that actually holds your subform. MyButton is the name of the button on your subform whose code you want to run. Let me know if you need any clarification.
ASKER
I apologize but are you referring to a field when you say control?
No - let me explain a bit further. Subforms are held inside "subform controls". This acts as a container for the form that is acting as a subform. If you design your main form, then click once on the subform, click View->Properties, you'll see the subform control's name in the Name property on the Other page. This is often (but not always) the same as the name of the form it contains, if you created it using the wizard. Otherwise, it might have a name like "Child11". The form that the subform control "holds" is determined by the Source Object property.
ASKER
Forms!frmtelephone!subfrmt ele.Form.c ommand13_O nClick What is wrong with this code?
That looks right - what error did it give?
Did you change the Private to Public?
Did you change the Private to Public?
ASKER
inproper reference to the property form/report. I am using Access 2k and my library references (not that it matters but I've come across this issue several times in my db and had to do some crazy stuff)
VB for apps
ms access 9.0 object library
ms access DAO 3.6 object library
ole automation
ms forms 2.0 object library
VB for apps
ms access 9.0 object library
ms access DAO 3.6 object library
ole automation
ms forms 2.0 object library
Sorry, try this, my error:
Forms!frmtelephone!subfrmt ele.Form.c ommand13_C lick
(i.e. remove the On)
Forms!frmtelephone!subfrmt
(i.e. remove the On)
ASKER
Same error...
Private Sub Form_Close()
Select Case MsgBox("Do you want to save?", vbYesNo, "Save Changes")
Case vbYes
Forms!frmtelephone!subfrmt ele.Form.C ommand13_C lick
Private Sub Form_Close()
Select Case MsgBox("Do you want to save?", vbYesNo, "Save Changes")
Case vbYes
Forms!frmtelephone!subfrmt
Can you post the command button's code from the subform (including the Sub and End Sub lines)?
ASKER
Public Sub Command13_Click()
Dim TRN_Eff As String
DoCmd.SetWarnings False
If IsNull(Me.TELE_Date) = True Then
TRN_Eff = False
Else: TRN_Eff = True
End If
If TRN_Eff = False Then
Select Case MsgBox("Do you want to save?", vbYesNo, "Save Changes")
Case vbYes
MsgBox "Please Enter A Date", vbExclamation
Me.TELE_Date.SetFocus
Case vbNo
If Dirty = True Then
DoCmd.RunCommand acCmdUndo
End If
End Select
End If
If TRN_Eff = True Then
Select Case MsgBox("Do you want to save?", vbYesNo, "Save Changes")
Case vbYes
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenQuery "qrycra1"
CurrentDb.Execute "Delete * From tblcra1"
Me.Requery
Case vbNo
If Dirty = True Then
DoCmd.RunCommand acCmdUndo
End If
End Select
End If
End Sub
Dim TRN_Eff As String
DoCmd.SetWarnings False
If IsNull(Me.TELE_Date) = True Then
TRN_Eff = False
Else: TRN_Eff = True
End If
If TRN_Eff = False Then
Select Case MsgBox("Do you want to save?", vbYesNo, "Save Changes")
Case vbYes
MsgBox "Please Enter A Date", vbExclamation
Me.TELE_Date.SetFocus
Case vbNo
If Dirty = True Then
DoCmd.RunCommand acCmdUndo
End If
End Select
End If
If TRN_Eff = True Then
Select Case MsgBox("Do you want to save?", vbYesNo, "Save Changes")
Case vbYes
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenQuery "qrycra1"
CurrentDb.Execute "Delete * From tblcra1"
Me.Requery
Case vbNo
If Dirty = True Then
DoCmd.RunCommand acCmdUndo
End If
End Select
End If
End Sub
That all looks correct - the "Invalid reference to property form/report" seems to suggest that the name of the subform control is incorrect. Can you double check it? If not, there is another (uglier) way to do it, but I'm not certain why this doesn't work.
ASKER
both name and source object is subfrmtele.
Ok, try this:
Me!subfrmtele.SetFocus
Me!subfrmtele.Form!Command 13.SetFocu s
SendKeys "{ENTER}"
Me!subfrmtele.SetFocus
Me!subfrmtele.Form!Command
SendKeys "{ENTER}"
ASKER
This is an issue throughout the DB and I was thinking the reference library maybe an issue.
Ah - when you say it's an issue throughout the db, where does it tend to give you that error?
This *sometimes* indicates database corruption although that wouldn't be the first conclusion. Have you compacted the database recently?
This *sometimes* indicates database corruption although that wouldn't be the first conclusion. Have you compacted the database recently?
ASKER
Yes I have compacted the db. I shouldn't say that it's throughout the db. It's everytime I refer to a subform.
Could you try the snippet that I posted above,with SendKeys?
ASKER
I have tried it with another form and the same issue.
That's very strange - are you using any of the Microsoft Forms 2.0 controls? Could you try unchecking that library and see if it works?
ASKER
It won't let me uncheck. It says it is in use
Are you able to reference controls on the subform? For example, if you run this line of code somewhere on your main form:
MsgBox Me!subfrmtele.Form!SomeTex tbox
Substitute MyTextBox with the name of a control on the subform - does it correctly give you a message box showing the value in the text box?
MsgBox Me!subfrmtele.Form!SomeTex
Substitute MyTextBox with the name of a control on the subform - does it correctly give you a message box showing the value in the text box?
ASKER
Hey I think I have found out what the issue was. My relationships were not there. I have no idea why that happened.
I will try the reference again
I will try the reference again
ASKER
the reference you supplied is working now! So now how do I keep the close event from happening
I missed that bit, sorry. You'll have to move the code to the form's Unload event. Then, you can prevent the form from closing with this line:
Cancel=True
This cancels the Unload event and keeps the form open.
Cancel=True
This cancels the Unload event and keeps the form open.
ASKER
Well still having a bit of an issue ...my save record above isn't happening. Hey I am done this evening. I have to be up in a few hours. Thanks and I will get you the points because you have spent an abnormal amount of time on this because of my relationships.
Thanks for everything
Thanks for everything
OK, post back when you return and we can try to troubleshoot the remaining problem.
ASKER
Sure will. Thanks
ASKER
Thanks.