Mmm, yes I suppose "does not work" is not very helpful!!! What I mean is when is Click the buttons....nothing happens....I mean nothing. But when I Click the Exit button, then it closes the Form as it should do.
Here are the codes:-
Private Sub Exit_This_Page_Click()
On Error GoTo Err_Exit_This_Page_Click
I am a bit confused. Because the "Close Page" button worked without reference to any Parent page, I just presumed the 'Delete' and 'Go To Last Record' Buttons would work in the same manner? No worries.
Thanks for the code - I changed it with the name of the Form and got the following error message.
But my main reason for wanting a Menu in a SubForm is because I have the same Menu on most of my Forms - so any changes I make to the one Menu/Subform will automatically apply to all the Forms that include the Menu/Subform. So I only have to make the change once - have I explained that OK??
So, I don't really want to specify the name of one particular Form to which the Menu/Subform is connected - I would like it to be 'general'. can I somehow specify a Parent Form which would close whichever Form the SubForm was attached to??
1. According to the documentation of Access 2003 (MSDN): "In Microsoft Access 97, the DoMenuItem method was replaced by the RunCommand method. The DoMenuItem method is included in this version of Microsoft Access only for compatibility with previous versions."
2. Again, this kind of command depends on the context and works with the active object (here a form). When you click on a button in a (sub)form, this (sub)form is the active object. Unfortunately, contrarily to the GotoRecord method, DoMenuItem does not allow you to optionally specify the object to which the command must be applied nor does RunCommand. You could try to set the focus on a control of the parent form, making the form the active one (not sure, I haven't tested this).
3. There is another solution that consists in deleting the current record of the parent's recordset, then move to the next record:
Private Sub Command_Delete_Click()
Dim rst As DAO.Recordset
Set rst = Me.Parent.Recordset
If Not rst.EOF Then
Set rst = Nothing
I don't know why the wizard in Access 2000 and Access 2003 still uses the deprecated syntax (I can guess, though). All I did was repeat what's written in the documentation of Access 2003 and on Microsoft's MSDN site: DoMenuItem Method [Access 2003 VBA Language Reference]. I wanted to verify if there were additional parameters (like with GotoRecord) that could solve the problem.
I tested the code before posting it and it works. The only problem you could encounter with it is that any possible states of the parent form and its recordset are not tested: no recordset (unbound form), no parent form, etc.
If you really want to systematically work with a subform that contains the command buttons of its parent form, you should seriously consider examining the sample database I posted or create an equivalent mechanism, probably an event-driven one, which is the most logical way of doing it (that's how Access itself works), but that can be difficult to understand if you're not familiar with programming with events.