Use mouse wheel scrolling within textbox in Access VBA

This article is about how to make mouse wheel scrolling in textbox. We are providing some VBA code on mouse wheel event that would enable scrolling on the text field. Basically MS Access does not have property of scrolling on the from text box. We have following procedures to do that.

Create a blank form and insert a text box as shown in Fig 1.1. Now set the scroll bars property to value vertically.

Use mouse wheel scrolling within textbox in Access VBA Fig-1.1

Fig-1.1

Create a new module as shown in fig 1.2 and write some VBA code to declare constant and function as given below.

Use mouse wheel scrolling within textbox in Access VBA Fig-1.2

Fig-1.2

Now go in the Form view and a blank text field with vertical scroll bars is there as shown in Fig 1.3. Now put some text lines in the text box so you can test wheel scrolling. So now it would enable you to scrolling on text field.

Use mouse wheel scrolling within textbox in Access VBA Fig-1.3

Fig-1.3

VBA code for ON Mouse Wheel event is mention below:-

Private Const modename = " db form"
Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
Dim LinesToScroll As Integer
Dim hwndActCtl As Long
Dim a As Long
If ActiveControl.Properties.Item("controltype") = acTextBox Then
hwndActCtl = funx(Screen.ActiveControl)
For a = 1 To Abs(Count)
SendMessage hwndActCtl, WM_VSCROLL, IIf(Count < 0, SB_LINEUP, SB_LINEDOWN), 0&
Next
End If
End Sub

VBA code for On Module is mention below:-

Private Const modename = "Scrolltextbox"
Public Const WM_VSCROLL = &H115
Public Const WM_HSCROLL = &H114
Public Const SB_LINEUP = 0
Public Const SB_LINEDOWN = 1
Public Const SB_PAGEUP = 2
Public Const SB_PAGEDOWN = 3
Private Declare Function focus Lib "user32" Alias "GetFocus" () As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) _As Long Function funx(ctl As control) As Long
On Error Resume Next
ctl.SetFocus
If Err Then
funx = 0
Else
funx = focus
End If
On Error GoTo 0
End Function


DISCLAIMER

It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. Access Guru will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.