Trapping SubForm Events/names

G

Guest

Your mission, if you choose to accept it………

I made an earlier posting regarding disabling the Replace tab on the
find/replace dialog box. Thanks to frekazeud, I was directed to the The
Access Web (mvp) where I “saw the lightâ€. As a result I figured out how to
disable Replace on forms, forms w/subforms and forms w/subforms that have
subforms. The latter is causing me the most frustration. I have formA which
has a TabCtrl with 3 Tabs. I currently have search buttons on the master and
all subforms with the master search button visible from all Tabs and
Subforms. Each subform also has its own search button, no problem if users
click the associated search button, but……, if they can, they will. Before I
can hide the subform search buttons I need to make the master search button
work better. The easy way would be to hide the unavailable search buttons,
but, who said it was going to be easy.
Here’s the layout of formA.
Tab1 has fields based on the source table, no problem.

Tab2 has a subform1 (master/child to formA fields) that has subform1a
(master/child to subform1), both have searchable fields.

Tab3 has subform2 (master/child to formA fields) that has subform2a
(master/child to subform2). Subform2 has no searchable fields, subform2a does!

Events are incestuous on subforms with subforms. For example when I use the
on_enter of subform1a, the on_enter of subform1 also fires, sometimes. The
got_focus of subform1 does not fire when moving between subform1a and
subform1 because subform1 already has focus because you’re already in
subform1 when you’re in subform1a and on and on. This is important because
the Find/Replace needs to know from where it is being called, or it defaults
with the Replace tab visible.

I am trying to trap the [sub form control] name and use a select case to
process the appropriate code. So far it works OK if used in the right
sequence, and only once, but…….. Also when I use the “.parent†for the
[Screen.PreviousControl] or was it the [sub form control] .Parent, I’m
getting soooo confused, I’m getting the TabName.

I am currently using the on_click of each field to send the
“SubFormControlname†to a ScratchForm, but it is also developing some issues
and only acceptable because I only have a few controls on my current
subforms.

Any ideas on how I might trap the [subform control name] (or is there
something better to trap?) ?
Thanks
 
T

TC

IMHO your question is really not very clear. I suggest you rephrase it
in terms of what you want to achieve from an "end user" viewpoint. For
example: "I want that when the user goes to a new record in the
subform, the ABC button on the main form is enabled so the user can
click it" - or somesuch. Then we could comment on what programming code
you would need, to achieve that.

HTH,
TC [MVP Access]
 
G

Guest

Sorry for the confusion. What I want is for the end user to be able to click
the search button on the master form(FormA) and for the Replace Tab to be
disabled every time.

What is happening now is that if the user jumps between search fields and
Subforms repeatly ( back and fourth) the Replace Tab starts to reappear. When
"Replace" reappears and I expand the "Look in" box, I see the form.caption of
the appropriate form when in SubForm1. When in SubForm1a the "Look in" box is
disabled but displays the TableName of SubForm1a. I am thinking that when the
"Replace" Tab reappears the user could become confused or even worse make
changes that would create "orphan records". Another concern is that as the DB
grows and the search is on "all fields", the search could become time
consuming
Thanks for your time.
 
G

Guest

TC,
As Gilda used to say on SNL, "never mind". Your comment made me revisit my
screens. I have combo boxes on the forms with no default values. It looks
like "Replace" reappears when the combobox is null. I now have a place to
start looking. Sometimes it takes a third eye to see! By the way, what does
"IMHO" mean?

Thanks again
 
T

TC

IMHO = "in my humble opinion". Used when you want to say that this is
just your own opinion, other people may have different opinions. "Red
is nicer than Blue, IMHO".

Cheers,
TC [MVP Access]
 
G

Guest

Thanks for the IMHO info. I thought I had a handle on the problem re: combo
box, but, I find the onClick does not fire until you expand the list. When I
can clearly state what's happening I will make another post.
Thanks
 
G

Guest

TC
Got 'er done(I think, IMHO). Thanks for the ear. Now if I can turn it into a
function rather than a form event I'll be a happy camper(not real good at
functions). But, I do have a question. Is there a way to cange the ".caption"
of the Find/Replace dialog box? I want it to say "Find" rather than "Find and
Replace".
Thanks
 
T

TC

There's no way to change the captions on the standard Find/Replace box
AFAIK ("as far as I know") - except perhaps for using Windows API
calls. And I doubt that you'd really want to go there, just for that
task. If you /did/ want to go there, you'd need to start by getting a
"window spy" tool, to see which parts of the find/replace box had
"window handles" or "hWnds". If you do not understand those terms,
you'd need to do some preliminary reading on how window management
works in Microsoft Windows.

Cheers,
TC [MVP Access]
 
G

Guest

TC
TDFM Sorry to be a pest but this time I think I really have a question.
Refer to previous posting for form layout. I haven't been able to find any
examples in the KB or newsgroups.

I call this from a cmdButton on FormA after clicking a control on SubForm1a

Dim GoPrev as Variant
GoPrev = Screen.PreviousControl returns SubForm1Control Name
Then
I issue a GoToControl back to the control I clicked before the cmdButton
This literal works
With Forms!FormA!SubForm1ControlName!SubForm1aControlName.Form
.AllowAdditions = False
' .AllowDeletions = False
.AllowEdits = False
End With
DoCmd.RunCommand acCmdFind
-------------------------------------------------------
Dim pmmForm, pmmSubForm1, pmmSubForm1a As Variant
pmmForm = PMMfrm.Name assigns FormA Name
pmmSubForm1 = GoPrev assigns SubForm1 Control Name
pmmSubForm1a = PMMctl.Parent.Caption assigns SubForm1a Control Name
Dim SrchVar As Variant
These all come from ActiveForm and ActiveControl values because of the
GoToControl statement.

‘Generates Error: Can’t find form points to With (SrchVar) with the correct
value displayed in error window.

SrchVar = ("Forms" & "!" & pmmForm & "!" & GoPrev & "!" & pmmSubForm1a)
With Forms(SrchVar)
‘.AllowAdditions = False
' .AllowDeletions = False
.AllowEdits = False
End With
DoCmd.RunCommand acCmdFind

Generates Error: requires object and points to .allowedits

With ("Forms" & "!" & pmmForm & "!" & GoPrev & "!" & pmmSubForm1a & “.Formâ€)
.AllowAdditions = False
' .AllowDeletions = False
.AllowEdits = False
End With
DoCmd.RunCommand acCmdFind
-----------------------------------------------------

What I want is to use variables to build the “with†statement so I can make
the code portable. Can this be done?

Thanks
 
T

TC

See if this helps.

Referrng to a subform is a little tricky. You do not need the name of
the subform! You need the name of the subform /control/ on the main
form.

If AAA is the name of the main form, and BBB is the name of a subform
/control/ on that form, this will set some form-level attributes of the
subform in that sunbform control:

with forms("AAA").controls("BBB").form
.allowadditions = false
.allowdeletions = false
etc.
end with

If the form &/or control names are in variables:

S1 = "AAA"
S2 = "BBB"
with forms(S1).controls(S2).form
and so on.

PS. AAA, BBB, S1 an S2 would not be good names to use! I've just used
those names to make it clearer "what goes where", in the example.

HTH,
TC [MVP Access]
 
T

TC

PS. In looking at your code again, I see that you already understand
what I said above. I just think you have the details a bit mucked-up.
Try it the way that I wrote it.

Cheers,
TC [MVP Access]
 
G

Guest

TC
I didn't think I'd hear back until Monday, Thanks! I'm going to try to
figure this out. Looks like I have a weekend project. Here is how I
understand what you said.

with forms("AAA").controls("BBB").form...
meaning literal values with quotes
....aaa = " FormAName", bbb = "Subform1ControlName"
.allowadditions = false
.allowdeletions = false
etc.
end with

If the form &/or control names are in variables:

S1 = "AAA"....
hope this could be the result of a Screen.........and does not require a
literal
pmmForm = PMMfrm.Name

S2 = "BBB"....
pmmSubForm1 = GoPrev

I get GoPrev from the B4GotoControl which is the SubFormControlName for
SubForm1 which also contains SunForm1a control. I think I need this info for
my conditional traps so I can build the correct variables for the with
statement.

I'm probably duplicating steps here because when I got my error messages the
"PMMctl.Parent.Caption" displayed no values when I was sent back to the
module window and placed my cursor on the expression member but got values if
the "member" was a variable(?)( I've never caught on to the debug window,lame
excuse)


with forms(S1).controls(S2).form...
with forms(pmmForm ).controls(pmmSubForm1 ).form
and so on.
This looks right for getting to SubForm1's control but SubForm1 also has a
SubForm called Subform1aControlName.Sooooo
wouldn't I need a
S3 = "CCC"...
pmmSubForm1a = PMMctl.Parent.Caption( I store the subformcontrolname in the
caption of the subform sourceobject, I think, but I get the correct value
,SubForm1aControlName.

Therefore...to mimick
with forms!FormAName!SubForm1ControlName!SubForm1aControlName.form
wouldn't I need..
with forms(S1).controls(S2 & S3).form...
with forms(pmmForm).controls(pmmSubForm1 & pmmSubForm1a ).form...

As I said, TDFM, I think I have a problem with the syntax for combining the
variables so they look like literals to Access. Don't I have to do some " '
", ' ! ', kind of syntax to make the S2 & S3 look like...

....).controls(SubForm1ControlName!SubForm1aControlName).form in the code ?

I get so spun around I don't even know if I'm explaining it right but I
think I have stated this correctly, TDFM! This stuff is like playing music,
some play by ear and others have to claw and scratch for every note. I belong
to the latter. I will be claw'n and scratch'n til I get it.
Appreciate the help
Paddy
 
G

Guest

TC
answered my own question!

With Forms(pmmForm).Controls(pmmSubForm1).Controls(pmmSubForm1a).Form
gets me to the subform on the subform.

This one single line has done the trick. Now all I have to do is develop the
traps to build the correct "With" statement. Thanks!

P.S. If I can get this done in a"clean" manner, I would like to "share"
this with other clawn' and scratchn' users. Do you have a prefered "posting
place"? I'm sure I'm not the only one who wants to hide the Replace tab.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top