Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't focus a form field?

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Why am I not able to place focus on a form field and and the carret at the end of the content?

Code:
Dim zoomCtl As Access.TextBox
  Dim ctl As Object
  
  Set zoomCtl = Me.inputTextBox
  Set ctl = BoundControl.Parent
  
  Do While Not TypeOf ctl Is Access.Form
    Set ctl = ctl.Parent
  Loop
  
  Set oControl = BoundControl
  
  Set Me.Recordset = ctl.Recordset
  
  With zoomCtl
    .ControlSource = BoundControl.ControlSource
    .Locked = BoundControl.Locked
    .ValidationRule = BoundControl.ValidationRule
    .ValidationText = BoundControl.ValidationText
    .Format = BoundControl.Format
    .ControlTipText = BoundControl.ControlTipText
    .ForeColor = BoundControl.ForeColor
    .TextAlign = 1
  End With
  

' THIS CODE BELOW DOESN'T SEEM TO WORK ?

    Me.inputTextBox.SetFocus
    If Not IsNull(Me.inputTextBox) Then
        Me.inputTextBox.SelStart = Len(Me.inputTextBox)
    Else
        Me.inputTextBox.SelStart = 1
    End If

When the form opens the control doesn't have focus and if the textbox has content the carret is not at the end ?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
What do you mean by "carret"? I am reading "^".

What does have focus are there any errors? Does the form have focus?
 
The form has the focus (carret is name for cursor)

There are no errors.

I have the same issue with the underlying form.

I use the following...
Code:
    If Nz(Me.Notes, "") <> "" Then
        Me.Notes.SetFocus
        Me.Notes.SelStart = Len(Me.Notes)
        Me.Notes.SelLength = 0
    End If

The notes field get focus only rather than the carret being placed at the end of the content of the memo field, instead it highlights some of the text randomly in the middle of the content?

How , I have SelStart = Len(me.Notes)
and the selLength = 0 , how can it possibly be highlighting any text with those commands?

Does this not work in Access 2010 or summing?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 

Where do you have the code mentioned above? In Form's Activate? Initialize?

Can you set your field's TabIndex to 0 ?

Just a guess here...

Have fun.

---- Andy
 
I have the code in a subroutine that is called after the popup form is closed....

Code:
Private Sub docNotes_DblClick(Cancel As Integer)

    Call inputZoom("Documents Request Notes")

    Do Until Not IsLoaded("inputPopUp")
        DoEvents
    Loop

    If bPopZoomChanged Then
    
        Call setDocs(Me.Docs_Form.Form, Me.Adviser)
        
        If Nz(Me.docNotes, "") <> "" Then
            Me.docNotes.SetFocus
            Me.docNotes.SelStart = Len(Me.docNotes)
        End If
    
    End If
    
End Sub

so i have a form field with a dblclick event, that popus up a large form, and binds the textbox to the large form for a 'zoom' feature.

if the content of the textbox changes, it sets a flag, when the form closes, the above code continues, and it should simply refocus the textbox and move the cursor to the end of the content.

Only it doesn't it randomly selects text in the middle of the textbox.

I have also used a msgbox to check the starting length before text is added and the length of the content after and although len(me.docNotes) , shows as having increased correctly , the cursor does not get placed at that position by the command me.docNotes.selStart = len(me.docNotes).

I can't be the only one with this phenomenon?






"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
As your code is in an event procedure of the control you want to set the focus to, you should set the focus to another control before:
Code:
...
        If Nz(Me.docNotes, "") <> "" Then
            Me.[i]AnotherControl[/i].SetFocus
            Me.docNotes.SetFocus
            Me.docNotes.SelStart = Len(Me.docNotes)
        End If
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
already tried that, doesn't make any difference!

it still seems to select text in the middle of the content?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
Does that procedure you call change the text property of the control by chance or is the record dirty? If I understand correctly you may do better with the following.

Code:
Me.docNotes.SelStart = Len(Me.docNotes[red].Text[/red])
 
doesn't make any difference, it is highlighting part of the content?

Another wierd phenomenon I just noticed is that even with "Enter Key Behaviour" set to 'New Line in Field" , enter key still acts as tab key instead?

Access 2010 drives me nuts, I'm sure Access worked better in 2003!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
ok, a decompile, and re-import of everything into a new DB solved the enter key issue!

Still highlighting random content though?

I think it's time to give up and move on, I will have to move the focus away from the input text box, it's too risky leaving it focused when text is highlighted incase they press a key and wipe out data!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
ok, i've worked out what causes the funkiness, but not why it happens?

I have a dblclick event which open the popup form, all works fine....

i have the following on the close event handler....
Code:
    oControl.SetFocus
    oControl.Requery
    If Not IsNull(oControl) Then
        oControl.SelStart = Len(Me.inputTextBox)
    End If

now if I do nothing else the carret stays at the end of the content exaxtly as expected ... however...

If I run any code what so ever when the popup form closes from the underlying form such as....
Code:
Private Sub docNotes_DblClick(Cancel As Integer)

    Call inputZoom("Documents Request Notes")
    
    Do Until Not IsLoaded("inputPopUp")
        DoEvents
    Loop

    [b]If bPopZoomChanged Then
        Me.Last_Check = Format(Now(), "dd/mm/yyyy")
        Me.Checked_By = oUser.Name
    End If[/b]
        
End Sub
So when the popup closes the dblclick event continues and updates two fields.

Then the funkiness happens where the carret highlights random text in the docNotes field.

So as long as I do nothing else within the event handler after the popup form opens , everything is fine, as soon as I try to update any form fields, the carret does the funky chicken!

Why is this happening?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top