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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to detect when form has scrollbar 1

Status
Not open for further replies.

deBassMan

Technical User
May 26, 2004
13
GB
Hi all

Using MS Access 2000, Win XP

I require a way of detecting whether a vertical scrollbar is visible on a sub-form.

thanks
 
Are you talking about the verical scrollbar put onto a grid automatically by Access or one that you have put on a form yourself?



Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
I am not aware of any way to trap for this. Who knows, I may learn something today if someone knows how to trap for this.

Good question.


Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
You can test for the value of me.form.scrollbars.

Scrollbars method = byte

0 = no bars
1 = horizontal only
2 = verticle only
3 = both

Code:
dim bytBars as Byte

bytBars = Me.Form.Scrollbars

  If bytBars = 0 Then
   msgbox "There are currently no scrollbars detected."
    Else
   msgbox "There is at least one scrollbar detected."
  End If

Cheers =)




~Melagan
______
"It's never too late to become what you might have been.
 
Thanks for the post. To further, I do not have access in front of me. Can the same thing be taken down to the control level.

For instance a multiline text box

bytbars = me.txtwhatever.scrollbars

or is this just at the form level?


Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
Are you talking about the verical scrollbar put onto a grid automatically

I am not sure of the answer, but I disagree that the above code tests for what debassman is asking. That code simply test the scrollbar property. To test this make a form and put this code in
MsgBox Me.Form.ScrollBars
If you expand the form so that no scrollbars show the value will be the same as the property. Shrink it until scrollbars show and it returns the same value.

I would think you have to do this using the forms hwnd property and using API.
 
MajP,

Now that I read debassman's post more closely and reading your own, I'm inclined to agree with you. Unfortunately, I do not know how to test of the verticle scrollbar currently exists on the form - only the form's scrollbar property.




~Melagan
______
"It's never too late to become what you might have been.
 
Somewhere I have Windows API code to do this. However, I would suggest posting the question in the Windows API forum if no one chimes in here.
 
Here is the VB code
Code:
Option Compare Database
Option Explicit


Private Const GWL_STYLE = (-16)
Private Const WS_HSCROLL = &H100000
Private Const WS_VSCROLL = &H200000

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Sub testScroll()
    Dim wndStyle As Long
    ' Retrieve the window style of the control.
    wndStyle = GetWindowLong(Form_Form1.hwnd, GWL_STYLE)
Debug.Print wndStyle & "  " & WS_VSCROLL & " " & WS_HSCROLL
    ' Test if the horizontal scroll bar style is present
    ' in the window style, indicating that a horizontal
    ' scroll bar is visible.
    If (wndStyle And WS_HSCROLL) <> 0 Then
        'MsgBox "A horizontal scroll bar is visible."
    Else
       ' MsgBox "A horizontal scroll bar is NOT visible."
    End If
  
    ' Test if the vertical scroll bar style is present
    ' in the window style, indicating that a vertical
    ' scroll bar is visible.
    If (wndStyle And WS_VSCROLL) <> 0 Then
        'MsgBox "A vertical scroll bar is visible."
    Else
        'MsgBox "A vertical scroll bar is NOT visible."
    End If
End Sub

However I could not get this to work with an Access Form.
These are the values I get when I debug.print

Debug.Print wndStyle & " " & WS_VSCROLL & " " & WS_HSCROLL
1456406528 2097152 1048576

I think I am not clear on the differences between the VB and Windows scrollbars.
 
Hi MajP

thanks for your reply

interesting code - however sadly I cannot get it working either.

But I think we're closing in on a solution -can anyone help??
 
Any luck? I tried to use this fIsScrollBar and fIsScrollBarHZ functions, but it returns the the windows handle regardless if the scrollbar is visible or not. This is basically the same problem I had with the previous code returning the window style.
 
I have this from DevX:


Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Const GWL_STYLE = (-16)
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000

Function HasHorizontalScrollbar(ctrl As Control) As Boolean
HasHorizontalScrollbar = (GetWindowLong(ctrl.hwnd, _
GWL_STYLE) And WS_HSCROLL)
End Function

Function HasVerticalScrollbar(ctrl As Control) As Boolean
HasVerticalScrollbar = (GetWindowLong(ctrl.hwnd, GWL_STYLE) And WS_VSCROLL)
End Function


Using these functions should be easy:

If HasVerticalScrollBar(List1) Then
' List1 is displaying a vertical scrollbar
End If


This code is not dissimilar to code above.

Either way it returns 3 whether a Vscrollbar is visible or not.

Can't help feeling it's an hwnd issue.


 
Sorry - should have said - above code written for VB6.

also Access forms do not seem to have hwnds like normal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top