Run Function from sub from in parent form?

CocodaMonkey

New member
Local time
Today, 02:15
Joined
Oct 3, 2008
Messages
4
I'm trying to run a function from a subform from an onclick event in the parent form.

The sub form is called ClientAddfrm and the function is
Code:
Public Sub clearaddclientbut_Click()
 DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End Sub

So all I want to do is wipe the sub form clean. Which the function does just fine if it's on an event in the sub form but if I go to the main form and call it by using "Call Me.ClientAddfrm.Form.clearaddclientbut_Click" it doesn't work. Although it does call the function because if I add something like "msgbox test" to the end of my function it displays the message.

I'm assuming it doesn't wipe my sub form because the focus is on the wrong form but I've tried everything i can think of to set the focus to the sub form before calling the function and I just can't get it to work.

All I need to do is wipe the bound subform clean of all information when it losses focus and I just can't figure out a way to do it.
 
The problem is that you're using

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

which is the old menu item to "undo" changes before they're saved or committed to the table. Because you've already left the subform, the record has already been committed, and your only option at this point is to delete the just saved subform record, not undo it.

Maybe someone here has a hack for doing this. In my practice I never use subforms for data entry.
 
No need to use the subforms code to start a new record on the sub form ...

Code:
Public Sub clearaddclientbut_Click()
    Me.ClientAddfrm.Form.Recordset.AddNew
End Sub

Then you can keep you sub form procedure as a Private procedure, which is generally my preference.

...

But ... I am confused as to why you want to clear the subform? ... or maybe its better stated, do you truly want to UNDO your changes to the record you are editing (new or otherwise) in the sub form upon loss of focus? ... if so, then maybe an UNBOUND form would be a better choice.
 

Users who are viewing this thread

Back
Top Bottom