473,466 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Memo field scrolls to top on losing focus

1,287 Recognized Expert Top Contributor
I have a text box bound to a memo field. Regardless of where I've scrolled down to in the text box, when I click out of it, it returns to the top. Is there any way to prevent this?
Thanks in advance,
Chip
Oct 6 '09 #1
11 7783
missinglinq
3,532 Recognized Expert Specialist
I did something like this a few years ago for somebody and the only way I could get it to work was to
  1. Create a second form with the same Record Source
  2. Add the one memo field
  3. Strip this form of everything you can, Nav buttons, Control box, Dividing line, etc. so you only have the memo field showing
  4. Go back and add this second form as a subform to the original form
Now you can scroll thru the memo field, and when you click out of it to another control on the main form, the memo field will remain in the same place.

This was done for someone who only needed to scroll thru the memo field to reference its contents. If you edit the memo field and leave it, it will return to the begging of the text. I could never figure out an answer to this. Maybe you or someone else can, if needed.

Linq ;0)>
Oct 7 '09 #2
ChipR
1,287 Recognized Expert Top Contributor
Looks like I'll have to go the subform route for now. Thanks for the tip, and I'll let you know if I come up with an alternative.
Oct 7 '09 #3
NeoPa
32,556 Recognized Expert Moderator MVP
I wouldn't think there would be a way to be fair. Is it just me or would you not expect the control to lose its edit position once the focus is lost? I know Memo fields are often fuller and need scrolling more than other types of field in a TextBox, but would this not be the standard behaviour of a TextBox control generally?
Oct 7 '09 #4
ChipR
1,287 Recognized Expert Top Contributor
Certainly this is a reasonable standard behavior. I just want a way around it for my application.
Oct 7 '09 #5
NeoPa
32,556 Recognized Expert Moderator MVP
I can't think of anything better than Linq's suggestion then Chip. I'm pretty sure all attempts to select what is displayed would get reset as soon as you left the subform involved. Sorry.
Oct 7 '09 #6
FishVal
2,653 Recognized Expert Specialist
Seems like a good way around is to store edit position in an additional field of a bound table. Edit position could be saved to the table in OnExit event handling code which is being triggered just before control loses focus.
Oct 9 '09 #7
ChipR
1,287 Recognized Expert Top Contributor
That's a good point Fish.

To be more specifi, the text box that I have is actually only for viewing puposes. It lists notes that have been added to the memo field. Another text box is used for typing in new notes, then a button appends the new note to the memo field. With the subform, I can scroll down the notes, then click out and go add a new one and it won't reset to the top, but of course when the data is updated, it automatically scrolls to the top.

Perhaps I can save the length of the field in a local variable before I append to it, then scroll it back to that length afterward.
Oct 9 '09 #8
mshmyob
904 Recognized Expert Contributor
Hello ChipR,

Here is something I threw together using API's (my first attempt so no laughing).

It does what you want albeit a little slow with the scrolling. Unfortunatly just moving the scrollbox does not update the contents and I cannot get the 'sendmessage - user32' api to work.

Anyways try out the demo and let me know. If you improve on it please re-upload so I can see what you did.

I saved it in AC2003 format.

cheers,
Attached Files
File Type: zip scrollOnFocus.zip (63.4 KB, 284 views)
Oct 10 '09 #9
mshmyob
904 Recognized Expert Contributor
I noticed a bug after I was cleaning up the code and I removed something I shouldn't have.

try this version instead of the previous.

cheers,
Attached Files
File Type: zip scrollOnFocus.zip (62.5 KB, 277 views)
Oct 11 '09 #10
FishVal
2,653 Recognized Expert Specialist
Hello, mshmyob.

Without getting into discussion about feasibility of the WinAPI solution (comparatively to native SelStart and SelPos properties of Access.Textbox class) I would like to emphasize flaws of your implementation of WinAPI method.

  • Expand|Select|Wrap|Line Numbers
    1. Private Declare Function FlatSB_GetScrollInfo Lib "comctl32" (ByVal hwnd As Long, ByVal fnBar As Long, lpsi As SCROLLINFO) As Boolean
    2. Private Declare Function FlatSB_GetScrollPos Lib "comctl32" (ByVal hwnd As Long, ByVal code As Long) As Long
    3. Private Declare Function FlatSB_SetScrollPos Lib "comctl32" (ByVal hwnd As Long, ByVal code As Long, ByVal nPos As Long, ByVal fRedraw As Boolean) As Long
    4.  
    All these functions are available in "user32" lib there is no need to use "comctl32" library.
    Scrollbar API
  • As far as I remember this child window (window class - "OKttbx" in Access 2003) which Access places over active control is being actually moved after GotFocus event has been handled. The window parameters you get using hWnd returned by GetFocus() API function are those for the previous state (rendered over a control which is about to loose focus).
  • And the last but not the least - SendKeys() which sends keys to whatever window is currently in focus. This is noticeable particularly in a case when
    Expand|Select|Wrap|Line Numbers
    1. Do While SI.nPos <> lngLastKnownPos
    2.     SendKeys "{DOWN}", True
    3.     FlatSB_GetScrollInfo Me.fhWnd, SB_VERT, SI
    4. Loop
    5.  
    becomes infinite due to (I guess) the previous paragraph.
Oct 13 '09 #11
StewartW
1 New Member
@missinglinq
Thank you so much.This was a huge help. StewartW, South Africa
Jan 18 '20 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Shyguy | last post by:
I want to create two buttons on a form. One would allow the user to Copy the contents of the current records memo field, the other would allow them to print. I set up a report based on the memo...
3
by: GorDon | last post by:
Hi, I have a report based on a query. The query grabs a memo field from my main table, yet when I display the memo field in the report it truncates the memo field (the field needs to hold more...
3
by: John | last post by:
I have a field, data type Memo, in a job details table. I have a text box on a report which I need to print the contents of this field. My problem is that the text box will only display 255...
2
by: Kevin | last post by:
Thanks for the very quick response posting that I can use a memo datatype to store large amounts of text. I understand that I can turn on "Can Grow" for a memo type, but is there either a...
4
by: Mark Reed | last post by:
Hi All, here is what I am trying to achieve. I have a memo field on a form which users will need to add to as and when. I do not want them to be able to edit information which already exists...
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
5
by: LabGeek | last post by:
I have an Access application that I have created that collects data from a scanner and from a weighting scale. The data from the scanner are unique identifiers (barcodes) and the scanner is...
2
by: bennylynch | last post by:
Hi, I am attempting to fill in 2 memo fields in the same form, which is fine, however the information on the second memo field is based on the information on the first one, so I need to hold the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.