Subform Events (1 Viewer)

WayneRyan

AWF VIP
Local time
Today, 11:12
Joined
Nov 19, 2002
Messages
7,122
I've got a coworker that is developing an app.
He's trying to dynamically assign a subform's RecordSource.

He swears that (through Google) the only events available are the OnEnter
and OnExit events.

That's true for the subform control itself, but the FORM itself does support them.

I briefly looked at the subform's OnCurrent event and it was empty.
In design view prior to his "dynamicness", there was code for the event.

Assigning [Event Procedure] to the OnCurrent property made it try to run
code, but it just said "can't find [Event Procedure].

Any ideas ???

I'll look further tomorrow at work.

Thanks,
Wayne
 

GinaWhipp

AWF VIP
Local time
Today, 07:12
Joined
Jun 21, 2011
Messages
5,901
Well, one that is not accurate because there are several ways you can change the Recordsource of a subform. That said, what is the event that causes the Subforms recordset to change? Is there a button that gets clicked? A field that gets updated? Is it On_Open of the main Form? Or perhaps a the After_Update event of a Combo Box?
 

WayneRyan

AWF VIP
Local time
Today, 11:12
Joined
Nov 19, 2002
Messages
7,122
Hi Gina,

From what I saw briefly was that upon selection of a table name in a list box, the
Subform's recordsource is set,

The sub form contains 255 unbound text boxes.

Access apparently assigns the columns to the control sources of the text boxes.
The sub form is then requeried and properly displays the data.
The navigation bar shows the correct record count and one can switch between
Rows in the form ... but no events.

As I mentioned earlier, I looked at the .OnCurrent property of the subform and
It was empty. I set it to [Event Procedure] and at least something happened.

Could not run "Event Procedure] ...

If you design the subform after, the code page is there.

I only spent a few minutes, but thought I might take a look at it tomorrow
With a few ideas of where to look.

Apparently, he had Googled and found numerous discussions where it was a
Known problem of events not firing on subforms. That's what got my
Attention because that's never been my experience.

Maybe .. I know that in design view forms have a "has module" setting.

Thanks,
Wayne

P.s. Not bad for a good typist ... forced to type on an IPAD !!!!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:12
Joined
Feb 19, 2013
Messages
16,553
found numerous discussions where it was a Known problem of events not firing on subforms
Don't think it is a 'known problem', just user ignorance about what events fire when and in what order
 

GinaWhipp

AWF VIP
Local time
Today, 07:12
Joined
Jun 21, 2011
Messages
5,901
Hmm, so few observations...

From what I saw briefly was that upon selection of a table name in a list box, the
Subform's recordsource is set,
Then you can set the Subforms recordsource in the On_Click event of the List Box

The sub form contains 255 unbound text boxes.
This is a HUGE ref flag! Sounds like this database is being set up like an Excel Spreadsheet. Perhaps if we know the business model this database is supposed to address we can better assist.

Access apparently assigns the columns to the control sources of the text boxes.
No *Access* doesn't assign anything the person creating the database does.

The sub form is then requeried and properly displays the data.
The navigation bar shows the correct record count and one can switch between
Rows in the form ... but no events.
Don't understand what you mean by the above

As I mentioned earlier, I looked at the .OnCurrent property of the subform and
It was empty. I set it to [Event Procedure] and at least something happened.

Could not run "Event Procedure] ...
If there is nothing on the the *[Event Procedure]* then nothing will run. No error can be generated because nothing is there.

If you design the subform after, the code page is there.
Design the Subform after what? Code does not just appear. Maybe you are talking the Recordsource.

Apparently, he had Googled and found numerous discussions where it was a
Known problem of events not firing on subforms. That's what got my
Attention because that's never been my experience.
I'm not sure what this person is putting in *the Google* but this is not a known problem. As CJ_London stated, sounds like User ignorance.

Maybe .. I know that in design view forms have a "has module" setting.
Having *Has Module* set to *Yes* does not mean there actually is a Module. Could mean at one time there was VBA there but it was removed but the Form's Module didn't clean itself up after Compact and Repair (which I can say happens and I often have to just set it to *No*).

I think what we have here is a novice trying to design a database. We welcome such folks so perhaps you should invite said person to join us? :D
 

MarkK

bit cruncher
Local time
Today, 04:12
Joined
Mar 17, 2004
Messages
8,178
You can also handle subform events on the main form, if you want, using the withevents keyword, like...
Code:
private [COLOR="Blue"]withevents[/COLOR] m_sfm as form

private sub Form_Open(Cancel as integer)
[COLOR="Green"]   ' set withevents variable to the subform object[/COLOR]
   set m_sfm = me.subformcontrol.form
[COLOR="green"]   ' ensure subform object raises Current event[/COLOR]
   m_sfm.OnCurrent = "[Event Procedure]"
end sub

private sub m_sfm_Current()
[COLOR="green"]   ' handles current event from subform object[/COLOR]
   msgbox "Current just fired on " & m_sfm.name
end sub
...or any other class that raises events.
hth
Mark
 

WayneRyan

AWF VIP
Local time
Today, 11:12
Joined
Nov 19, 2002
Messages
7,122
Mark, Gina

This guy has been using Access for about ten years.

He is trying to make a universal display subform.
He has a subform with 255 unbound text boxes.
By just setting the Recordsource he actually displays the data, but no code works. He has msgboxes in all the events, but none are called.

I'm gonna look at it tomorrow, he must have done something to make the events not work.

I obviously can't learn anything in design mode ... I'll have to run it and
See what is changing. Been a while and not as familiar with all the
Properties/methods/syntax.

Thanks,
Wayne
 

GinaWhipp

AWF VIP
Local time
Today, 07:12
Joined
Jun 21, 2011
Messages
5,901
Well, I have been doing this for more than 10 years (not going to say how long :rolleyes:) and in all that time I have never even seen a subform with that many controls on it.

Will wait to hear back.
 

JHB

Have been here a while
Local time
Today, 12:12
Joined
Jun 17, 2012
Messages
7,732
..
This guy has been using Access for about ten years.
..
I have had staff who have used MS Access for many years without knowing how databases should be built and no sense of VBA code, so to use is not the same as understanding. :)
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:12
Joined
Feb 19, 2013
Messages
16,553
I briefly looked at the subform's OnCurrent event and it was empty.
In design view prior to his "dynamicness", there was code for the event.
this implies that the 'dynamic' code removes the onCurrent code, or perhaps since this code presumably runs outside of the subform - not stated but the listbox click event on a the parent form perhaps? the code changes the subform sourceobject? Suggest look at the subform in layout view rather than design view, you can then see what is actually there at runtime

He has msgboxes in all the events, but none are called.
I'm sure you don't mean all events, there are hundreds of them. Do you mean all control click events or got focus events for example?

If you mean just the form events, events like open and load only occur when the form is first opened, activate does not work on a subform
 

Users who are viewing this thread

Top Bottom