call the "on current" on parent form

H

HB

Is there any way to call the "on current" event of a parent form from a
subform? I don't want to "requery" the parent form, though, is that the only
way to have the "on current" event processed?
 
P

PC Datasheet

You can programatically set focus to a field on the parent form and then
programatically go to some record (next, previous or whatever).

Me.Parent!ControlOnParent.SetFocus
DoCmd.GoToRecord,,acNext
 
H

HB

Actually, i need the form to run code in the Form_Current sub. but I'm
assuming this is impossible. Is the solution to write my own sub and call it
on "on focus" event?

tia
 
H

HB

and does me.parent really work? or do i need the parent's actual name? (newb
forms coder here)

thanks again.

HB
 
P

PC Datasheet

You could change Private Sub Form_Current() to Public and then call it with:
Call Form_Current()
 
V

Van T. Dinh

You can call the (Main Form's) Current Event from the Subform's code if you
declare the Form_Current Event of the main Form as Public rather than
Private.

I think you can also use an ObjectVariable declared with "WithEvents" but
this is a bit more advanced.
 
M

Mark Burns

Van T. Dinh said:
You can call the (Main Form's) Current Event from the Subform's code if
you
declare the Form_Current Event of the main Form as Public rather than
Private.

....won't the VBA compiler object to changing that from private to public?
(sounds like a bad idea, COM interface-wise, anyway)
I think you can also use an ObjectVariable declared with "WithEvents" but
this is a bit more advanced.

That would be my approach.
....but even simpler:

In parent form Code:
public sub FireCurrent()
form_current
end sub

in subform code:
....
'using EARLY-binding...
Dim oFrm as [Form_<your_parent_form_name_here>]
set oFrm = Me.Parent
'note this will only work if you *know* that this form will only have *1*
"parent" form
oFrm.FireCurrent
set oFrm = nothing

'or...using LATE binding...
Dim oFrm as Object '(or also, possibly you could use: Form)
set oFrm = Me.Parent
'this will work if there might be multiple "parent" forms, but...
oFrm.FireCurrent
'if this public sub/function isn't present in the then-current "parent"
'form at run-time...*BOOM!*
'you could use an 'on error resume next' prior to the
' oFrm.FireCurrent ro avoid the error,
'but then it could fail silently...
'which could be ok, or just as bad, or even worse
'...depending on your App's needs.
set oFrm = nothing

- Mark
 
V

Van T. Dinh

See comments in-line.

--
HTH
Van T. Dinh
MVP (Access)


...won't the VBA compiler object to changing that from private to public?
(sounds like a bad idea, COM interface-wise, anyway)
No problems in VBA here.




That would be my approach.
...but even simpler:

In parent form Code:
public sub FireCurrent()
form_current
end sub

in subform code:
...
'using EARLY-binding...
Dim oFrm as [Form_<your_parent_form_name_here>]
set oFrm = Me.Parent
'note this will only work if you *know* that this form will only have *1*
"parent" form
oFrm.FireCurrent
set oFrm = nothing

'or...using LATE binding...
Dim oFrm as Object '(or also, possibly you could use: Form)
set oFrm = Me.Parent
'this will work if there might be multiple "parent" forms, but...
oFrm.FireCurrent
'if this public sub/function isn't present in the then-current "parent"
'form at run-time...*BOOM!*
'you could use an 'on error resume next' prior to the
' oFrm.FireCurrent ro avoid the error,
'but then it could fail silently...
'which could be ok, or just as bad, or even worse
'...depending on your App's needs.
set oFrm = nothing

You can use IsLoaded to check whether the Main Form is open/loaded or not.
 
Top