SelLength not working (1 Viewer)

smig

Registered User.
Local time
Today, 16:55
Joined
Nov 25, 2009
Messages
2,209
SelLength not working is not working for a sub form.
It will select all text

Code:
 me.Materials_SubForm.Form.MaterialDescription.SetFocus
 me.Materials_SubForm.Form.MaterialDescription.SelLength = 0
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:55
Joined
Oct 29, 2018
Messages
21,358
Try adding SelStart=1.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:55
Joined
Oct 29, 2018
Messages
21,358
Not working :(
Okay, "not working" means what, exactly? Did you get an error? Can you post a sample copy of your db? It might be faster to figure out what you're trying to do, if we could see it.
 

smig

Registered User.
Local time
Today, 16:55
Joined
Nov 25, 2009
Messages
2,209
Okay, "not working" means what, exactly? Did you get an error? Can you post a sample copy of your db? It might be faster to figure out what you're trying to do, if we could see it.

It means it select all text :(
it work OK if the Text box is on the main form, but not on a sub form :banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:55
Joined
Oct 29, 2018
Messages
21,358
It means it select all text :(
it work OK if the Text box is on the main form, but not on a sub form :banghead:
Okay, if a subform is involved here, then it may be a matter of using the correct syntax. Can you post a sample copy of your db, so we can tell you what syntax you could use?
 

smig

Registered User.
Local time
Today, 16:55
Joined
Nov 25, 2009
Messages
2,209
Okay, if a subform is involved here, then it may be a matter of using the correct syntax. Can you post a sample copy of your db, so we can tell you what syntax you could use?

This is the most weird ever :banghead:
If i cause an error by not moving the focus to that txtBox and then debug and move the focus there and let the code continue to run it will select what I'm looking for.
If I let the code run as it should (move the focus to that txtBox) and then try to select what I want it will select the entire text :eek:
 

moke123

AWF VIP
Local time
Today, 10:55
Joined
Jan 11, 2013
Messages
3,849
If i cause an error by not moving the focus to that txtBox and then debug and move the focus there and let the code continue to run it will select what I'm looking for.
If I let the code run as it should (move the focus to that txtBox) and then try to select what I want it will select the entire text

What exactly are you trying to select if not the entire text?
Is there more code than what you have shown?

provided you have the proper reference and can set the focus to the textbox
try something like

Code:
me.yoursubform.form.textboxname.setfocus
me.yoursubform.form.textboxname.SelStart = 0 ' or whatever place you want to start
me.yoursubform.form.textboxname.SelLength = len(me.yoursubform.form.textboxname) ' or whatever length you want
 
Last edited:

missinglinq

AWF VIP
Local time
Today, 10:55
Joined
Jun 20, 2003
Messages
6,423
Code:
 me.Materials_SubForm.Form.MaterialDescription.SetFocus
 me.Materials_SubForm.Form.MaterialDescription.SelLength = 0

Do you not have to set Focus to the Subform Control itself...then to the Control on the Subform?
Code:
 Me.NameOfSubFormControl.SetFocus
 Me. NameOfSubFormControl.Form.ControlName.SetFocus
Linq ;0)>
 

smig

Registered User.
Local time
Today, 16:55
Joined
Nov 25, 2009
Messages
2,209
What exactly are you trying to select if not the entire text?
Is there more code than what you have shown?

provided you have the proper reference and can set the focus to the textbox
try something like

Code:
me.yoursubform.form.textboxname.setfocus
me.yoursubform.form.textboxname.SelStart = 0 ' or whatever place you want to start
me.yoursubform.form.textboxname.SelLength = len(me.yoursubform.form.textboxname) ' or whatever length you want

I'm trying to select only part of the text (A text I'm searching for)
 

smig

Registered User.
Local time
Today, 16:55
Joined
Nov 25, 2009
Messages
2,209
Do you not have to set Focus to the Subform Control itself...then to the Control on the Subform?
Code:
 Me.NameOfSubFormControl.SetFocus
 Me. NameOfSubFormControl.Form.ControlName.SetFocus
Linq ;0)>
No it's not that
 

smig

Registered User.
Local time
Today, 16:55
Joined
Nov 25, 2009
Messages
2,209
this code will case an error on the marked line.
If I debug and let the code continue from next line it will select what I need.
If I remove the error causing line (Or any other error causing line) it will select the entire text

Code:
        Me.MaterialName.SetFocus
        Me.MaterialName.SelLength = 0
        Call MaterialsFormTabsClicks(1)
        [B]Me.Materials_SubForm.Form.SetFocus[/B]
        Me.Materials_SubForm.Form.MaterialDescription.SetFocus
        Me.Materials_SubForm.Form.MaterialDescription.SelStart = InStr(Me.Materials_SubForm.Form.MaterialDescription.Value, strSearchSplit(0)) - 1
        Me.Materials_SubForm.Form.MaterialDescription.SelLength = Len(strSearchSplit(0))

If I put a MsgBox at the end I can see it select OK, but once I click the msgbox it will select the entire text :eek:
even an Exit Sub just after this won't help :mad:
 

Users who are viewing this thread

Top Bottom