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.
Create a new module as shown in fig 1.2 and write some VBA code to declare constant and function as given below.
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.
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&
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
If Err Then
funx = 0
funx = focus
On Error GoTo 0
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.
Copyright © 2019 ERP Makers