Toggle Challenge - Toggle button to show or hide a subform

T

Toucan

Dear all,

I want to create a form that will serve as a type of switchboard that will
permit me insert certain "canned" phrases into a field in another form. These
will be medical terms for Subjective findings, Objective findings and Plan.

The form would have 2 columns. In the left-hand column, I will have these
main categories and I was planning on giving each a Toggle button, that would
turn on or off what would appear in the right-hand column.

So, for example, when the "Subjective" toggle button is depressed, the
right-hand column would display a bunch of buttons and each would be
responsible for inserting a text string in a field in a different form.

My table of origin has 2 columns - one is Button_Category and the other is
Button_Name (which is the "canned" phrase I'll be inserting)

How do I make this happen?

Thanks
Toucan
 
A

Allen Browne

There are several challenges to getting this to work.

Firstly, let's define what you want. Is it:
a) just a quick way to insert phrases, which might then be edited by hand so
that they no longer match the original phrases you started with, or
b) boilerplate phrases that are to print out in order, but don't need to be
edited.

If (a), the target will be a memo field, and you will need to build a custom
toolbarn (or ribbon) to fire up the phrases. You cannot use toggle buttons
on a form. If you do, the subform (or memo field), when you click the
button it takes focus and the subform/memo loses focus. Consequently, it no
longer has the cursor in it. Since there is no insertion point, you don't
know where the text is supposed to be added, so it can't be done.The
toolbar/ribbon does not have this issue, but you will need to be comfortable
with designing your own toolbar or ribbon to make this work. If you have not
done it before, it's a bigger task than we can help you with in a newsgroup
post.

If (b), the target will be a related table where you store the foreign key
value for the boilerplate phrase. The table will have fields like this:
ID AutoNumber primary key
StudentID Number whatever the comments apply to (policy? quote?)
PhraseID Number relates to the primary key of your table of
phrases
SortOrder Number indicates the order to assemble these.

Your target subform will be a continuous form, so you can add the phrases by
selecting them. I'm not sure the toggle button is a great solution. This
would require some coding skills and some understanding of SQL to achieve.
Worse, each time you add another boilerplate phrase later, you have to
redesign your form by adding more toggle buttons. Perhaps a list box might
be easier? You would still need to code the AfterUpdate event procedure of
the list box to Execute an Append query statement to add a record to the
related table and then Requery the subform to make it show up.

If you don't have the coding skills to do that, it would be very simple to
add a brief descriptor field to the boilerplate table (i.e. a unique name
for each of the boilerplate phrases.) Your continuous subform could then use
a combo where you select the phrase you want by its name, which adds the
record to the related table. On the next row of the continuous subform, you
then add the new phrase, and so on. This approach is easy to use (select
from drop-down list), and requires no coding at all.
 
D

Dirk Goldgar

Allen Browne said:
If (a), the target will be a memo field, and you will need to build a
custom toolbarn (or ribbon) to fire up the phrases. You cannot use toggle
buttons on a form. If you do, the subform (or memo field), when you click
the button it takes focus and the subform/memo loses focus. Consequently,
it no longer has the cursor in it. Since there is no insertion point, you
don't know where the text is supposed to be added, so it can't be done.

Allen, I'm not sure I agree with you. It seems to me that you could use the
LostFocus or Exit event of the memo text box to capture the current
..SelStart property value (and .SelLength, if desired) into a module-level
variable. Then that information would be available for use by the code
behind a button to insert some text at that point. Have I overlooked
something that would make this impossible?
 
A

Allen Browne

You may be right, Dirk.

Lurking in the back of my memory, I tried that and there was some problem.
Can't recall if it was SelLength that was unavailable.
 
D

Dirk Goldgar

Allen Browne said:
You may be right, Dirk.

Lurking in the back of my memory, I tried that and there was some problem.
Can't recall if it was SelLength that was unavailable.


It's altogether possible you found some sort of problem, but I just made a
quick and simple test using Access 2003, and both SelStart and SelLength
seem to be available and usable in this way. I wasn't 100% sure whether
those properties would be available in the LostFocus event, but they were.

However, there's an interesting hitch I can think of. If the button being
clicked is on a different form object than the memo field (as, for example
if the button is on a parent form and the memo field is on a subform, then
switching from the memo field to click on the button won't trigger the memo
text box's LostFocus event -- the text box continues to have the focus of
the subform. In that setup, I think one would have to use the Exit event of
the subform to capture the info.
 
A

Allen Browne

Dirk Goldgar said:
... both SelStart and SelLength ...seem to be available ...
in the LostFocus event

... use the Exit event of the subform to capture the info.

Thanks, Dirk. I may have been using subforms.

In any case, the custom toolbar solution was a good one, ... until we got
ribbons in A2007.
 
G

ghiasi55

Dirk Goldgar said:
Allen, I'm not sure I agree with you. It seems to me that you could use
the LostFocus or Exit event of the memo text box to capture the current
.SelStart property value (and .SelLength, if desired) into a module-level
variable. Then that information would be available for use by the code
behind a button to insert some text at that point. Have I overlooked
something that would make this impossible?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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