Setting Focus on Continuous Form

S

scott

I have a subform that has a "Continuous Form" view. By default when the
parent form opens, the focus is on the first record of the sub form, which
is fine.

However, each record on the sub form has an command button to the right of
the values that I have an OnClick event set to open another form that needs
the sub form's active record id value. If the user selects the desired
subform record before clicking the command button, everything works.

The problem is that it's real easy to just click the command button without
selecting the subform record associated with the command button. When that
happens, the command button opens the "pop-up" form using the first subform
record id field value or the last subform record id field that was last
selected.

How can I force access to set the active record to the record "line" that
contains the command button clicked?

Thanks In Advance,

Scott
 
K

Ken Snell \(MVP\)

If the user scrolls to the desired record in the subform and then clicks the
command button in that record, that record will have the focus and its
values will be the ones "read" when the code from the button reads the
values. Your description of the problem suggests that this is not happening,
so I assume that the user is doing something other than scrolling down to
the correct record.

It's certainly possible to "move" the subform to the desired record
automatically -- but you need to tell us how the form is supposed to know
what the desired record is.
 
S

scott

Picture this. Your looking at the form/subform and the 1st record of the
subform is active. There are say 10 records on the subform and each record
has a command button (I'm using a image graphic) to the right of the record
values.

Without realizing that the first record of the subform is active, it's real
easy to click say the subform's 4th record's image graphic that opens the
pop-up form.

Does that make sense?
 
K

Ken Snell \(MVP\)

Yep, and that should make that fourth record have the focus for the code
that runs from the click event. Is the image graphic in the subform's Detail
section, or is it in a different section of the subform?
 
S

scott

it's in the subform's Detail section


Ken Snell (MVP) said:
Yep, and that should make that fourth record have the focus for the code
that runs from the click event. Is the image graphic in the subform's
Detail section, or is it in a different section of the subform?
 
K

Ken Snell \(MVP\)

Post the code that is running in the Click event of that "button".
--

Ken Snell
<MS ACCESS MVP>


scott said:
it's in the subform's Detail section

< snipped >
 
S

scott

I don't understand why this is happening, but here's the problem. I tried
the same thing using an Access generated command button. It works fine.

The embedded image that I inserted has different properties than an Access
generated bitmap command button. For some reason, it's click event thinks
the subform's current record is the one that's selected. The access
generated command button will behave fine, that is that it receives the
focus and makes it's record the active record on the sub form.

Why would an "inserted" bitmap's onclick event behave differently than a
standard access generated bitmap?
 
K

Ken Snell \(MVP\)

Without seeing your setup/form, or having more explanation about what it is
so that I can fully understand the object to which you're referring, it's
hard to be sure. But my guess is that the bitmap object on which you're
clicking is not capable of receiving the focus, thus the focus is not moved.

Put a transparent command button on top of the bitmap image in the Detail
section, and use the Click event of that transparent command button to run
your code. That should fix the problem.
 
B

Bob Hairgrove

Picture this. Your looking at the form/subform and the 1st record of the
subform is active. There are say 10 records on the subform and each record
has a command button (I'm using a image graphic) to the right of the record
values.

Are you reading the ID value directly from the subform's recordset (i.e. using
Me.ID), or is it being stored in a variable somewhere?

I'm assuming that you are using a real command button nand not a label orother
control which doesn't have an OnGotFocus event. I had a similar issue with a
hyperlink which I tried using a label, and I had exactly the same problemas
you. So I changed the hyperlink to a command button, and in the OnClick event I
called Application.FollowHyperlink with the URL set to what was stored inthe
table for that particular record. And it works now!

Try putting a message box in the button's OnGotFocus event procedure which shows
you the ID value. That event always runs before the OnClick event fires. Then it
will be easier to see what is going on.
 
S

scott

thanks, I think we can chalk it up the fact that an imported picture just
doesn't have a focus event. your workaround makes the best sense.
 

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