UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Text Box Scrollbar Not Visible Useless In Focus, Access 2016    
 
   
Redsafety1
post May 26 2020, 01:27 PM
Post#1



Posts: 8
Joined: 25-May 20



Hi all,

As per http://www.UtterAccess.com/forum/scrollbar...t-t1952081.html I also have a requirement to have certain textboxes for example 12 to have its scrollbar visible when it contains lots of text, even when they haven't clicked on it.
This is so there is a visual cue to indicate that there is more text in the box that is not visual to the user.

However, from my reading of news groups I understand that this is not available in Access and the only way to get a feature like this is to come-up with a workaround.

I have potentially identified an idea but it is reliant on knowing the amount of lines in the text box . I have found a potential codeing idea http://www.UtterAccess.com/forum/Count-num...e-t1949069.html example, however when I tried it I found the following issue for my use.:-

Whilst the code does a very good job counting with a line of text that does not wrap around, as soon as the text exceeds the width of the text box say 100 characters and wraps around I.e. starts a new line the algorithm interpret this action still as one line, when in fact it is multiple lines.

Can anyone assist me with my current dilemma using Access 2016?

Best regards
Go to the top of the page
 
mike60smart
post May 26 2020, 02:15 PM
Post#2


UtterAccess VIP
Posts: 14,034
Joined: 6-June 05
From: Dunbar,Scotland


Hi

If you go into Design View of the Form and select the Textbox

RightClick and select Properties and you can then set Scrollbar to Vertical as shown in the attached screenshot.

Attached File  scroll_bar.PNG ( 10.11K )Number of downloads: 0

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
June7
post May 26 2020, 03:04 PM
Post#3



Posts: 1,529
Joined: 25-January 16
From: The Great Land


Textbox still only shows scroll bar when textbox gets focus. I really don't know any way to force display. Long time ago I tried to find a way and gave up.

This post has been edited by June7: May 26 2020, 03:06 PM

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
GroverParkGeorge
post May 26 2020, 03:20 PM
Post#4


UA Admin
Posts: 37,504
Joined: 20-June 02
From: Newcastle, WA


Same here. I don't know of a way to force the scroll bar to be visible when the text box control does not have focus.

I wonder if you could use Conditional Highlighting to achieve a similar objective of letting the user know there is text beyond what is visible.

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
GroverParkGeorge
post May 26 2020, 03:20 PM
Post#5


UA Admin
Posts: 37,504
Joined: 20-June 02
From: Newcastle, WA


welcome2UA.gif

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
isladogs
post May 26 2020, 03:46 PM
Post#6


UtterAccess VIP
Posts: 2,400
Joined: 4-June 18
From: Somerset, UK


Suggest you read this lengthy thread at AWF which covers the same topic and provides more than one solution to the issue
https://www.access-programmers.co.UK/forums...ext-box.294529/

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
pere_de_chipstic...
post May 26 2020, 03:57 PM
Post#7


UtterAccess Editor
Posts: 10,668
Joined: 8-November 07
From: South coast, England


PMFJI
welcome2UA.gif

Stephan Lebans created a function fTextHeight that calculates the height of a control, which I modified slightly:
CODE

Option Compare Database
Option Explicit

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type


' Declare API functions
'Private Declare Function apiCreateFont Lib "gdi32" Alias "CreateFontA" _
(ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, _
ByVal W As Long, ByVal i As Long, ByVal u As Long, ByVal s As Long, _
ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, _
ByVal PAF As Long, ByVal f As String) As Long
Private Declare PtrSafe Function apiCreateFont Lib "gdi32" Alias "CreateFontA" _
(ByVal h As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, _
ByVal W As Long, ByVal i As Long, ByVal U As Long, ByVal S As Long, _
ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, _
ByVal PAF As Long, ByVal F As String) As LongPtr 'OK

'Private Declare Function apiSelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare PtrSafe Function apiSelectObject Lib "gdi32" (ByVal hdc As LongPtr, ByVal hObject As LongPtr) As LongPtr 'OK

'Private Declare Function apiDeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Long) As Long
Private Declare PtrSafe Function apiDeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As LongPtr) As Long 'OK

'Private Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long 'OK

'Private Declare Function apiMulDiv Lib "kernel32" Alias "MulDiv" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Private Declare PtrSafe Function apiMulDiv Lib "kernel32" Alias "MulDiv" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long 'OK

'Private Declare Function apiCreateIC Lib "gdi32" Alias "CreateICA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Any) As Long
Private Declare PtrSafe Function apiCreateIC Lib "gdi32" Alias "CreateICA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DEVMODE) As LongPtr 'OK

'Private Declare Function apiGetDC Lib "User32" Alias "GetDC" (ByVal Hwnd As Long) As Long
Private Declare PtrSafe Function apiGetDC Lib "user32" Alias "GetDC" (ByVal hwnd As LongPtr) As LongPtr 'OK

'Private Declare Function apiReleaseDC Lib "User32" Alias "ReleaseDC" (ByVal Hwnd As Long, ByVal hdc As Long) As Long
Private Declare PtrSafe Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As LongPtr, ByVal hdc As LongPtr) As Long 'OK

'Private Declare Function apiDeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Long) As Long
Private Declare PtrSafe Function apiDeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As LongPtr) As Long 'OK

'Private Declare Function apiDrawText Lib "User32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare PtrSafe Function apiDrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As LongPtr, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long 'OK


' size of a device name string
Const CCHDEVICENAME = 32
' size of a form name string
Const CCHFORMNAME = 32

Type DEVMODE
dmDeviceName(0 To CCHDEVICENAME - 1) As Byte
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName(0 To CCHFORMNAME - 1) As Byte
dmUnusedPadding As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
'#if(WINVER >= 0x0400)
dmICMMethod As Long
dmICMIntent As Long
dmMediaType As Long
dmDitherType As Long
dmReserved1 As Long
dmReserved2 As Long
' #if (WINVER >= 0x0500) || (_WIN32_WINNT >= _WIN32_WINNT_NT4)
dwPanningWidth As Long
dwPanningHeight As Long
' #endif
'#endif /* WINVER >= 0x0400 */
End Type

' CONSTANTS
' Allow Left and Right margins in the Control.
Private Const lngFudgeMargin = 5
' How many Twips are in an Inch
Private Const TWIPSPERINCH = 1440
' Used to ask System for the Logical pixels/inch in Y axis
Private Const LOGPIXELSY = 90
' DrawText() Format Flags
Private Const DT_TOP = &H0
Private Const DT_LEFT = &H0

'Private Const DT_SINGLELINE = &H20
'Private Const LOGPIXELSX = 88
'Private Const DT_NOCLIP = &H100

Private Const DT_CALCRECT = &H400
Private Const DT_WORDBREAK = &H10
Private Const DT_EDITCONTROL = &H2000

Public Function fTextHeight(ctl As Access.TextBox, strCtlText As String, Optional blCR As Boolean = False) As Integer

'Name FUNCTION() fTextHeight
'
'Purpose: Returns the Control Height needed to
' display the contents of the string passed
' to this function. This function
' uses the Control's current Width and its
' font attributes to create a Font
' for the required calculations.
'
'Version: 3.0
'
'Calls: Text API stuff. DrawText performs the actual
' calculation to determine Control Width/Height
'
'Returns: Height of Control in TWIPS required
' to display current contents.
'
'Created by: Stephen Lebans
'
'Credits: Anybody who wants some!<grin>
'
'Date: July 15, 2000
'
'Time: 11:22:17pm
'
'Feedback: Stephen@lebans.com
'
'My Web Page: www.lebans.com
'
'Copyright: Lebans Holdings Ltd.
' Please feel free to use this code
' without restriction in any application you develop,
' whether private or commercial.
' This code may not be resold by itself or as
' part of a collection.
'
'
'Bugs:
'Not tested enough to tell. Let me know
'NEEDS ERROR CHECKING!!!!!
'
'Enjoy
'Stephen Lebans

'Modified: pere_de_chipstick (UtterAccess)
'Date: January 27, 2015
'Time: 14:00
'Modification Added code to automatically factor for vertical scroll bar (if used)

'***************Code Start***************
On Error Resume Next

' Structure for DrawText calc
Dim sRect As RECT

' Handle to Report's window
Dim hwnd As Long

' Reports Device Context
Dim hdc As Long

' Holds the current screen resolution
Dim lngYdpi As Long

Dim newfont As Long
' Handle to our Font Object we created.
' We must destroy it before exiting main function

Dim oldfont As Long
' Device Context's Font we must Select back into the DC
' before we exit this function.

' Temporary holder for returns from API calls
Dim lngRet As Long

' Calculate screen Font height
Dim fheight As Long

Dim intScrollFct As Byte

Dim intVar As DEVMODE

' If the user has pressed the Enter Key let's see
' if the string still fits within the control.
' We do this by cheating a bit and not caring where they
' were when the Enter key was pressed. We'll just add a vbCrLf
' to the front of the string.
If blCR Then strCtlText = vbCrLf & strCtlText


' Get Controls Parents Window handle
hwnd = ctl.Parent.hwnd
If hwnd = 0 Then
hwnd = Forms!FrmDbSetup.hwnd
If hwnd = 0 Then Exit Function
End If

' retrieve a handle to a display device context (DC)
' for the client area of the specified window
hdc = apiGetDC(hwnd)

' Because Access control's do not have a permanent Device Context,
' we cannot depend on what we find selected into the DC unless
' the Control has the focus. In this case we are simply using the
' Control's Font attributes to build our own font in whatever
' DC is handy. We must Save this DC's Font so we can restore
' the Font when we exit this function.

' Clear our return value
lngRet = 0

' Temporary Information Context for Screen info.
Dim lngIC As Long

' Get current Screen resolution in Pixels per inch
lngIC = apiCreateIC("DISPLAY", vbNullString, vbNullString, intVar)
If lngIC <> 0 Then
lngYdpi = apiGetDeviceCaps(hdc, LOGPIXELSY)
apiDeleteDC (lngIC)
Else
lngYdpi = 120 'Default average value
End If

' Calculate/Convert requested Font Height
' into Font's Device Coordinate space
fheight = apiMulDiv(ctl.FontSize, lngYdpi, 72)

' We use a negative value to signify
' to the CreateFont function that we want a Glyph
' outline of this size not a bounding box.
With ctl
newfont = apiCreateFont(-fheight, 0, _
0, 0, .FontWeight, _
.FontItalic, .FontUnderline, _
0, 0, 0, _
0, 0, 0, .FontName)
End With

' Select the new font into our DC.
oldfont = apiSelectObject(hdc, newfont)

' Use DrawText to Calculate height of Rectangle required to hold
' the current contents of the Control passed to this function.
' IF we pass a value in the .Right member of our RECT structure
' the DrawText will return the value in the .Bottom member required
' to fully display the control's contents.

With sRect
.Left = 0
.Top = 0
.Bottom = 0
' If you place a non zero value in the .Right member
' of the RECT structure than the value returned
' is based on a fixed width rectangle of the width
' you specified in the the .Right member.

If ctl.ScrollBars Then intScrollFct = 15 'Factor vertical scroll bar

.Right = (ctl.Width / (TWIPSPERINCH / lngYdpi)) - lngFudgeMargin - intScrollFct
lngRet = apiDrawText(hdc, strCtlText, -1, sRect, _
DT_EDITCONTROL + DT_WORDBREAK + DT_CALCRECT + DT_TOP + DT_LEFT)

' Cleanup
lngRet = apiSelectObject(hdc, oldfont)

' Delete the Font we created
apiDeleteObject (newfont)

lngRet = apiReleaseDC(hwnd, hdc)

' Convert RECT values to TWIPS
.Bottom = .Bottom * (TWIPSPERINCH / lngYdpi)

' We add .05 percent to allow for Top & Bottom margins in the Control.
fTextHeight = .Bottom + (.Bottom * 0.05)
End With

End Function


The function is called with the following code in the form's on current event and the control's on change event:

CODE

Dim intCurTextHeight As Integer
With Me.[YourTextboxname]
intCurTextHeight = fTextHeight(Me.[YourTextboxname], Nz(.Value, ""))
If intCurTextHeight > .Height Then
.BorderColor = vbRed
.BorderWidth = 2
Else
.BorderColor = vbBlack
.BorderWidth = 1
End If
Me.Repaint
End With


This sets the border of the control red and the border width to 2 if the text is larger than can be displayed in the control

hth

--------------------
Warm regards
Bernie
Go to the top of the page
 
ADezii
post May 26 2020, 04:09 PM
Post#8



Posts: 3,089
Joined: 4-February 07
From: USA, Florida, Delray Beach


To the best of my knowledge, you cannot force the display of ScrollBars in a TextBox as you can in other Controls. What you can do is to have a Visual Cue that Text within a TextBox will have a Vertical ScrollBar, or Text length exceeds the vertical limits of the TextBox, once it receives the Focus. As an example, I'll use a Calendar Project that I have adapted many times over the years for specific use. The ScrollBars Property is dynamically controlled depending on the number of CrLf's in the TextBox. If it exceeds a certain amount then the ScrollBars Property is set to 2, if not, no ScrollBars will appear OnFocus. If Vertical ScrollBars are needed, the word (Expanded) will appear next to the Date. Notice the attached Image in which Text within these three Day Blocks will exceed the Vertical Limit of the Box and (Expanded) is displayed next to the Date. Once one of these Dates is selected (May 15, May 18, or May 19,2020) then the Vertical ScrollBar becomes Visible. I know that this is all very confusing, so if you need the actual DB, I would be happy to Upload it.
This post has been edited by ADezii: May 26 2020, 04:09 PM
Attached File(s)
Attached File  Calendar.JPG ( 132.86K )Number of downloads: 5
 
Go to the top of the page
 
isladogs
post May 27 2020, 12:24 AM
Post#9


UtterAccess VIP
Posts: 2,400
Joined: 4-June 18
From: Somerset, UK


That's a similar idea to the visual clues provided in the solutions offered in my link from my previous post
For example
Attached File  Capture.PNG ( 108.27K )Number of downloads: 11

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
Redsafety1
post May 27 2020, 01:19 PM
Post#10



Posts: 8
Joined: 25-May 20




Hi all,

A big thank you to everyone that has submitted a suggestion I appreciated your time and trouble in trying to resolve my dilemma.

Best regards.
Go to the top of the page
 
Redsafety1
post May 28 2020, 02:43 PM
Post#11



Posts: 8
Joined: 25-May 20



Hi Pere_de_chipstick

My eye focused on your suggestion as it displays a red border to flag a visual indicator that the user needs to use the scroll bar to see the rest of the text, this is the same idea I was working with.

To test your idea, I have created a new database and placed the first part of your code in a common module. The 2nd part after updating the two areas you highlighted with my text box name have been placed in the current event of the form and the change event of the text box.

Unfortunately, when I over fill the visual area of the text box, the text box border does not display red.

Could you advise what am I missing?
Go to the top of the page
 
pere_de_chipstic...
post May 28 2020, 04:46 PM
Post#12


UtterAccess Editor
Posts: 10,668
Joined: 8-November 07
From: South coast, England


Could you post a copy of your dB, - just the form and table - enough to show the problem. Makes sure you remove any sensitive data in your dB, compact and repair it, and then zip it before posting. And I'll be happy to take a look.

--------------------
Warm regards
Bernie
Go to the top of the page
 
Redsafety1
post May 29 2020, 08:29 AM
Post#13



Posts: 8
Joined: 25-May 20



Hi Pere_de_chipstick

Thank you for offering to take a look.
As you suggested I have created the most basic frame work to test your idea.

Regards
Attached File(s)
Attached File  TestDatabase1.zip ( 33.39K )Number of downloads: 2
 
Go to the top of the page
 
pere_de_chipstic...
post May 29 2020, 04:54 PM
Post#14


UtterAccess Editor
Posts: 10,668
Joined: 8-November 07
From: South coast, England


Hi Redsafety1

There is a small difference in the code for the on current and on change events that I had missed (oops! blush.gif)

In the On Change event the affected line is:
CODE
intCurTextHeight = fTextHeight(Me.txTask, Nz(.Text, ""))


while in the On Current event it should be
CODE
intCurTextHeight = fTextHeight(Me.txTask, Nz(.Value, ""))


hth

--------------------
Warm regards
Bernie
Go to the top of the page
 
Redsafety1
post May 30 2020, 06:22 AM
Post#15



Posts: 8
Joined: 25-May 20



Hi

I have updated as per your updated code statements. However I am expecting the boarder of Text6 to be red as there is more text in the box than is visible but it has not changed.
What am I doing wrong?
Go to the top of the page
 
pere_de_chipstic...
post May 30 2020, 08:52 AM
Post#16


UtterAccess Editor
Posts: 10,668
Joined: 8-November 07
From: South coast, England


Hi

I've attached your db updated,

I've bound the second text box - only to make it easier to see the record you're on and added '.SpecialEffect = ' and '.BorderStyle = ' lines in the code. Note that I've also added 'Option Explicit' at the top of the code module, which you should have at the top of all your code modules as it helps with debugging.

Remove a line from the first record (Text 6) and the border should go black, add the line again and it should go red.

hth
Attached File(s)
Attached File  TestDatabase1_Updated.zip ( 35.15K )Number of downloads: 4
 

--------------------
Warm regards
Bernie
Go to the top of the page
 
Redsafety1
post May 30 2020, 02:22 PM
Post#17



Posts: 8
Joined: 25-May 20



Hi Pere_de_chipstick,

Firstly, thank you for your time and trouble in trying to resolve my issue.

I have tried the database, but it still does not show the red boarder so I have run it via Office 2010 on a different laptop, I can report it works fine and your suggestion will certainly fulfil my requirements.

I have also tried the database in another laptop using windows 10 and office 2016 and can confirm in this case I get a compile error type mismatch module 1 and the following is highlighted hdc =ApigetDC

Give my requirement are for this to operate in an Office 2016 environment what modifications do I need to undertake for the textbox to display correctly?
Go to the top of the page
 
pere_de_chipstic...
post May 30 2020, 02:40 PM
Post#18


UtterAccess Editor
Posts: 10,668
Joined: 8-November 07
From: South coast, England


Hi Redsafety1

I am not sure I am able to help you on this error, the original application I used this on was A2007, however it has been tried and tested in Windows 10 with both Office 2016 32 and 64 bit. My current setup is Win 10 & Office 2016 32bit and it runs without problem.

I will put a shout out to see if anyone else can point you in the right direction.

--------------------
Warm regards
Bernie
Go to the top of the page
 
pere_de_chipstic...
post May 30 2020, 02:57 PM
Post#19


UtterAccess Editor
Posts: 10,668
Joined: 8-November 07
From: South coast, England


Hi Redsafety1

This is a long shot, but have you checked for any references (in the VBA window --> Tools --> References) for any references marked 'Missing', on the systems where the application doesn't work?

--------------------
Warm regards
Bernie
Go to the top of the page
 
ADezii
post May 30 2020, 06:52 PM
Post#20



Posts: 3,089
Joined: 4-February 07
From: USA, Florida, Delray Beach


Works fine on my PC with Office 365/32bit and Windows 10.
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search


RSSSearch   Top   Lo-Fi    11th July 2020 - 07:07 AM