Problem: Highlighted record in Subform when opened

Sorrells

Registered User.
Local time
Today, 16:52
Joined
Jan 13, 2001
Messages
258
I have several of these types of forms with subforms. When the form opens, most of the time the first record is highlighted. I do not know how to code to insure that this does not happen.

In the OnOpen event of the Main form I have code like below. Note that the subform does open at the first record but the Sendkeys seem to have no effect:

Forms![name of main form]![name of subform].Requery
DoCmd.GoToRecord, , acFirst
Sendkeys "{F2}"
Sendkeys "{HOME}"

If I could, I'd code so that no record in the subform could be fully selected (highlighted) but I also have not figured out this one either!
 
Hi,

What type of subform do you use? Datasheet or Continuous?
What do you expect from the sendkeys?
 
SforSoftware,

They are set at Continuous, although I admit I am not sure the significance of this, I think it is the default.

I had hoped that the SendKeys would:
F2 - unhighlight the record
HOME - place the cursor at the beginning of the text.

At this point, I am getting the form to open acceptably, with the cursor at the first (top) record, the record text is not highlighted and the cursor is blinking to the left of the text.

I am not sure what is happening (new to Access XP) but I found that the pared down code, today, works perfectly well:

Forms![name of main form]![name of subform].Requery
DoCmd.GoToRecord, , acFirst

My new problem, one that perhaps I should post as a new topic, is when the form/subform is open and the cursor is happily blinking in a record of the subform. If the User presses the ENTER key, the- cursor goes down one record which is just fine. But also the entire text becomes highlighted. I have not figured out how to remove this highlight.

The difficulty here is that Windows novices don't know what a highlighted text means, begin typing and find the entire text gone!

What do you think?
 
Okay, it seems to be clear to me now.

First: you use:
Forms![name of main form]![name of subform].Requery
DoCmd.GoToRecord, , acFirst
Only the first line is necessary, because after a requery the subform always select the first record.

Further:
Write this into a standard module:
Code:
Public Function SelectStart()
  On Error Resume Next
  Screen.ActiveControl.SelStart = 0
End function
In the GotFocus-property box of the fields you write "=SelectStart()". Now, when you come into the field, always the cursor is blinking before the first character.

With this function you dan Start after the last character in the textbox::
Code:
Public Function SelectEnd()
  On Error Resume Next
  Screen.ActiveControl.SelStart = Nz(Len(Screen.ActiveControl.Value), 0)
End function
And you use "=SelectEnd()" in the GotFocus-propertybox.
 
Would changing the settings under Tools>Options>Keyboard help?
 
Maybe, but that's the setting for each control, so use it as 'default' and for all others use the given functions.
 

Users who are viewing this thread

Back
Top Bottom