Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2005-04-29 : 02:56:56
|
Am I allowed to ask this question here?Here's the problem - Multiline text box on an Access form. When the user presses a button on the form, a value from the database is to be inserted where the insertion point was, before the user clicked the button (and lost focus). Before you jump in with SelStart and SelLength, note that Access appears to lose all knowledge about SelStart and SelLength after an OnChange event, although it knows where they are at the time of the OnChange event.I can't find anything on the internet or in Access help which describes the interaction between OnChange and SelStart.Is there anyone who knows enough about Access to answer this? No - I mean is there ANYONE who knows enough about Access to answer this...PS - I'm using Access 2003, but I believe the behaviour is the same on most versions.--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-04-29 : 05:29:14
|
If I understand your problem correctly, then I think this is the only wayPrivate Sub Text1_LostFocus()Dim l As Integerstr = Text1.SelTextl = Len(str)MsgBox Text1.SelText str = Text1.SelTextText1.Text = str & " sample " & Mid(Text1.Text, l, Len(Text1.Text))End SubAll you have to do is to select the text inside the text box from left to right and click the Command button. Now the Lost focus event of textbox will fire and the string " sample " will added at the last of sel end.Suppose the textbox1 initially has "This is the text" and you select "This is the "If you press the command button, the textbox1 value will be "This is the sample text"MadhivananFailing to plan is Planning to fail |
 |
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2005-05-01 : 19:30:41
|
No, Sorry if I wasn't clear...as I said in my post, quote: Before you jump in with SelStart and SelLength, note that Access appears to lose all knowledge about SelStart and SelLength after an OnChange event, although it knows where they are at the time of the OnChange event.
this doesn't work once you have made a change in the text box. Once a change is made Access appears to lose any knowledge of where the selection point is. By the time the control has lost focus, seltext = "" whether there is anything highlighted or not.Test your code and see what I mean. Go into the text control, enter a new line, back up using the arrow keys, select a section of text and then click outside the control. Access returns SelStart = 0, SelLength = 0 and SelText = "" Any other ideas?--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2005-05-03 : 01:37:35
|
If anyone is interested I have found a solution.First, I create an object which has attributes SelStart, SelLength and Text. onChange, onMouseUp and onKeyUp, I copy the attributes form the textbox control to the objectFrom then on, I refer to the values in the object and all is correct.--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-03 : 03:39:05
|
Good to know you get solutionI tested my method in VB and seems to work correctlyMadhivananFailing to plan is Planning to fail |
 |
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2005-05-03 : 03:41:00
|
Hey Madhivanan In VB or in Access?Do you really get a value from SelStart after doing the steps I suggested?Maybe its just an Access 2003 thing?--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-03 : 04:42:44
|
I tested my method at VB6. Still I didnot try your method. I think yours also will workMadhivananFailing to plan is Planning to fail |
 |
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2005-05-03 : 22:26:05
|
Yeah, I suspected that VB would be OK. This is definitely an Access thing.Cheers and Thanks--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
|
|
|
|