Move Cursor too, not just Focus

B

bhammer

Access 2003
The Main form has SubFormLeft and SubFormRight, both in datasheet view. The
current record on the Left list triggers the Right list to Requery to reflect
the current record on the Left (based on a Where query). This is fine.

Now I want the user to be able to key Down through the records on the Right
list immediately after clicking in whatever field (selecting a record) on the
Left list.

I tried in the Left subform's Current event:

Forms.Main.SubFormRight.SetFocus

This does in fact move the focus to the Right, but it leaves the blinking
cursor back in the text field on the Left side. This is bad because when the
user uses the Down key the focus is moved the next record on the Left,
instead of the Right (even though the Right had the Focus, ie highlight.)

Brad.
 
D

Dirk Goldgar

bhammer said:
Access 2003
The Main form has SubFormLeft and SubFormRight, both in datasheet view.
The
current record on the Left list triggers the Right list to Requery to
reflect
the current record on the Left (based on a Where query). This is fine.

Now I want the user to be able to key Down through the records on the
Right
list immediately after clicking in whatever field (selecting a record) on
the
Left list.

I tried in the Left subform's Current event:

Forms.Main.SubFormRight.SetFocus

This does in fact move the focus to the Right, but it leaves the blinking
cursor back in the text field on the Left side. This is bad because when
the
user uses the Down key the focus is moved the next record on the Left,
instead of the Right (even though the Right had the Focus, ie highlight.)


I'm not observing this in a quick test I set up. However, I'm not using a
requery for the "Right" subform; I'm just setting its LinkMasterField to a
hidden text box on the main form that picks up the value of the linking
field from the "Left" subform. My only code, in the Left subform, is

Private Sub Form_Current()

Me.Parent.sfRight.SetFocus

End Sub
 
B

bhammer

Dirk,

Did your cursor move along with focus? I wouldn't expect that it makes any
difference how the Right subforms recordset is produced, but I can try using
the LinkMasterField method you describe.

Just to make clear, my issue is not with producing the correct record list
on the Right subform, but to get the Focus (AND the cursor) to move from the
clicked field in the Left subform to the Right.

Brad
 
D

Dirk Goldgar

bhammer said:
Dirk,

Did your cursor move along with focus?

Define "cursor". The mouse pointer (generally referred to as the "cursor")
did not move, but the text caret (indicating where keystrokes will be
received) did. And keystrokes that I then made in my test did go into the
current control on the right-hand form, where I had set the focus.

It is possible to move the mouse pointer, but I don't see the point in that.

I wouldn't expect that it makes any
difference how the Right subforms recordset is produced, but I can try
using
the LinkMasterField method you describe.

I'm inclined to agree with you, but I just wanted to note that there was a
slight difference in how I set up my form.
Just to make clear, my issue is not with producing the correct record list
on the Right subform, but to get the Focus (AND the cursor) to move from
the
clicked field in the Left subform to the Right.

Understood.
 
B

bhammer

Dirk,

I modified my form to work using the LinkMasterField method, same as your
test, but the bahaviour is the same. Here's what happens:

When I click in a field of the Left subform the cursor enters the field at
the character location where I clicked, ready for editing. The "cell" is not
highlighted, meaning the entire field is not selected, but the blinking edit
cursor is in there.

In next split second the Right list is updated to reflect my current record
on the Left, and the focus moves to the first field of the first record on
the Right list, but my blinking edit cursor remains in the Left. (I can tell
where the focus is because I set Conditional Formatting for HasFocus for
fields in both subforms.)

And when I type or try to move to next record using the keyboard down arrow.
I edit the Left list field or move down one record in the Left subform.

Brad
 
M

Marshall Barton

bhammer said:
I modified my form to work using the LinkMasterField method, same as your
test, but the bahaviour is the same. Here's what happens:

When I click in a field of the Left subform the cursor enters the field at
the character location where I clicked, ready for editing. The "cell" is not
highlighted, meaning the entire field is not selected, but the blinking edit
cursor is in there.

In next split second the Right list is updated to reflect my current record
on the Left, and the focus moves to the first field of the first record on
the Right list, but my blinking edit cursor remains in the Left. (I can tell
where the focus is because I set Conditional Formatting for HasFocus for
fields in both subforms.)

And when I type or try to move to next record using the keyboard down arrow.
I edit the Left list field or move down one record in the Left subform.


I think you might not have moved the focus to the
highlighted record in the right side subform. To move the
focus to a control in a subform you need to, as per Dirk's
excellent explanation earlier this week, first move the
focus to the subform control on the main form and then move
it to a control in the subform.
 
D

Dirk Goldgar

bhammer said:
Dirk,

I modified my form to work using the LinkMasterField method, same as your
test, but the bahaviour is the same. Here's what happens:

When I click in a field of the Left subform the cursor enters the field at
the character location where I clicked, ready for editing. The "cell" is
not
highlighted, meaning the entire field is not selected, but the blinking
edit
cursor is in there.

In next split second the Right list is updated to reflect my current
record
on the Left, and the focus moves to the first field of the first record on
the Right list, but my blinking edit cursor remains in the Left. (I can
tell
where the focus is because I set Conditional Formatting for HasFocus for
fields in both subforms.)

And when I type or try to move to next record using the keyboard down
arrow.
I edit the Left list field or move down one record in the Left subform.


That's puzzling, because it is not what happened in my test. If you'd like
to send me a cut-down copy of your database, containing only the elements
necessary to demonstrate the problem, compacted and then zipped to less than
1MB in size (preferably much smaller) -- I'll have a look at it, time
permitting. You can send it to the address derived by removing NO SPAM and
".invalid" from the reply address of this message. If that address isn't
visible to you, you can get my address from my web site, which is listed in
my sig. Do *not* post my real address in the newsgroup -- I don't want to
be buried in spam and viruses.
 
D

Dirk Goldgar

bhammer said:
Dirk,

I modified my form to work using the LinkMasterField method, same as your
test, but the bahaviour is the same. Here's what happens:

When I click in a field of the Left subform the cursor enters the field at
the character location where I clicked, ready for editing. The "cell" is
not
highlighted, meaning the entire field is not selected, but the blinking
edit
cursor is in there.

In next split second the Right list is updated to reflect my current
record
on the Left, and the focus moves to the first field of the first record on
the Right list, but my blinking edit cursor remains in the Left. (I can
tell
where the focus is because I set Conditional Formatting for HasFocus for
fields in both subforms.)

And when I type or try to move to next record using the keyboard down
arrow.
I edit the Left list field or move down one record in the Left subform.


Brad -

I've looked at the database you sent me, and discovered that the behavior
shows itself when the left subform is in datasheet view, but not in
continuous forms view. When I tested before, I overlooked the fact that you
said your subforms were in datasheet view, and I tested with subforms in
continuous forms view.

I've sent you a version of the database in which I've replaced the datasheet
subform with a CF subform, and it works (for me, at least) as it should.
 
B

bhammer

Dirk Goldgar said:
Brad -

I've looked at the database you sent me, and discovered that the behavior
shows itself when the left subform is in datasheet view, but not in
continuous forms view. When I tested before, I overlooked the fact that you
said your subforms were in datasheet view, and I tested with subforms in
continuous forms view.

I've sent you a version of the database in which I've replaced the datasheet
subform with a CF subform, and it works (for me, at least) as it should.
Dirk

Strange, but true, the focus will not move to the field if the subform is in
datasheet view. I modified my db to make that subform a continuous form,
which has it's own quirks--I still would rather have the datasheet view--to
sort on any field, to resize columns, have moveable column headings, etc. but
the movefocus ability if priority right now . . .

Thanks for brainstorming with me.
-Brad
 
B

bhammer

Dirk Goldgar said:
Dirk

Strange, but true, the focus will not move to the field if the subform is in
datasheet view. I modified my db to make that subform a continuous form,
which has it's own quirks--I still would rather have the datasheet view--to
sort on any field, to resize columns, have moveable column headings, etc. but
the movefocus ability if priority right now . . .

Thanks for brainstorming with me.
-Brad

Dirk,

After a time, I decided I needed to switch my subform from continuous view
back to datasheet view. And now I found my solution. A DblClick from the user
in one of the fields in the Right subform has the following code that moves
the focus to the Left subform and then moves the hightlight to the first item
in the subdatasheet.

START CODE
Private Sub txtCode_DblClick(Cancel As Integer)
On Error Resume Next

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = Me.Parent.frmDefectListRight.Form.Recordset

'MsgBox "Start DblClick. SetFocus."
With Me.Parent.frmDefectListRight
.SetFocus
With rs
'MsgBox "RecordCount = " & .RecordCount
If .RecordCount > 0 Then .MoveFirst
End With
End With

End Sub
END CODE

Works great AND I get to keep the right subform in datasheet view!

-Brad
 

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