Putting Generic Buttons on a Subform

  • Thread starter Thread starter John Ortt
  • Start date Start date
J

John Ortt

Hi Everyone,

Just a quick question to see if it is possible to design a generic form with
"Save and close", "Undo and close" ,"Next" and "Previous" buttons which
affect whichever form it is added to as a subform?

I have tried the following (and variations) but I can't get it to work:

Private Sub cmdNext_Click()
Me.Parent.SetFocus
DoCmd.GoToRecord , , acNext
End Sub

Does anyone have any suggestions?

Thanks in advance,

John
 
The way I do that is a have a standard module I call modFormOperations. For
a short example, here is the function to close a form:

Public Function CloseForm(ByRef SomeForm As Form)
DoCmd.Close acForm, frm.Name, acSaveNo
End Function

To use it from a button on any form, just enter this in the Click event
property text box of the Properties Dialog in design mode:

=CloseForm(Forms!MyFormName)

The advantages of using this sort of technique:
1. Less work on your part
2. Things work consistently (Users like that)
3. The form stays lighter and therefore loads more quickly.

One other thing. Be consistent in control naming. That way, when you need
to address a control by name in one of your functions
 
I'm interested, too, but can't find the proper, safe, way to do "Save and
close", "Undo and close". Any good link? The example db below deals only
with record navigation
 
Save and close:
With Me
If .Dirty Then
.Dirty = False
End If
DoCmd.Close acForm, .Name
End With

Undo and close:
With Me
If .Dirty Then
.Undo
End If
DoCmd.Close acForm, .Name
End With

If the code goes into an unbound subform, replace the first line in each of
the above with this:
With Me.Parent

Add error handling of course: the attempt to set Dirty to false generates a
trappable error if the record cannot be saved for any reason (e.g. required
field missing.)
 
Thanks for the Help Everyone,

Stephen's record navigation is an excellent help and has solved most of my
problems.

The only minor issue I am still having is that the undo button I added to
Stephen's form will not work.

The following is the code I am using:

Private Sub cmdUndo_Click()
If Me.Parent.Dirty Then
Me.Parent.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.Close , , acSaveNo
Else
Me.Parent.SetFocus
DoCmd.Close , , acSaveNo
End If
End Sub

I think it is not working because by activating the subform the main form is
being saved making it clean.

If anyone knows a way around this I'd really appreciate it.

Thanks again,

John
 
No, It hasn't worked.

It still seems to be saving the record before accessing the subform.

Any suggestions?
 
If I understand what you're trying to do, I don't believe there's any way
around it.

If you've got a new record on the parent form, and you move to the subform
(or, more generically, you take focus off the parent form), the record on
the parent form is going to be saved.
 
Douglas J Steele said:
If I understand what you're trying to do, I don't believe there's any way
around it.

If you've got a new record on the parent form, and you move to the subform
(or, more generically, you take focus off the parent form), the record on
the parent form is going to be saved.

You have confirmed what I was afraid of......Thanks Doug
 
Yes, of course.

You don't like the toolbar button for Undo, John?

It solves a multitude of issues, since the user can click it at any time,
i.e. the user does not have to get out of the current field where they have
an invalid entry (such as the incomplete 1/1/ in a date field) before they
can access the command button on the form.
 
Back
Top