Reseting SelHeight and record selected

K

kdw

Here is the situation:
when a user selects a record in the subform and then clicks a button on the
main form, a letter (in Word) relating to the selected record is displayed.
However, when the user switches the view back to Acess, the record selector
goes back to the first record of the subform. This is problematic because
the user might execute another action not realizing that the selector has
moved.

Is there any way to either:
- have the record selector stays on the record previously selected
-"reset" whether any record is selected in a subform to 0, so that I can
display a message asking them to select the record if they want to perform
another action
 
A

Allen Browne

When you click the button, Access moves the focus to the button before it
runs the button's Click event. That means the multi-record selection is
always lost before command button's code is executed. You will never have
multiple records selected when a command button is clicked.

Workarounds:
- a custom toolbar button (since it is not moving focus on the form),
- a keyboard combination,
- a yes/no field in the subform's table, so the user can pick records.
 
K

kdw

Thanks for the input, Allen. I think I have seen an example of your 3rd
suggestion from someone on this forum ( I don't remember if it's from your
website or someone else. It's the selecting multiple Contacts and printing a
report example in case anyone else remembers.). I think that might be my
best bet, especially since I can see needing to process multiple
non-consecutive records.

but I am not familiar with your 1st and 2nd suggestions. Can you elaborate
and maybe I can tuck them in my back pocket for future use?
 
A

Allen Browne

Creating a custom toolbar is a fairly big topic, so you will need to look up
help on that. Essentially you customize the toolbar, create a new one,
Ctrl+drag any buttons you want to keep from the existing toolbar (dragging
would move them: Ctrl+drag copies them), add a custom button and assign a
macro/function to the button. The macro/function can check SelHeight etc for
Screen.ActiveForm. Could be problems for subforms.

The 2nd option involves setting the form's KeyPreview to Yes, and using its
KeyDown event to trap a particular key combination and give a custom
response which can include using SelHeight to get the selected records. Once
you have that info, be sure to explicitly save before doing anything else.
This will trigger a bunch of other events, and there can be issued with the
sequencing of those triggered events.

If you can solve the issue by adding a yes/no field to your table, and
showing it as a check box on the form, this will be the simplest approach.
If you need non-contiguous selections, the other 2 options won't be
adequate.
 

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