the internet is great, but you have to take the code as-is
for this reason I never use downloaded code unless I understand every single line of code (if something goes wrong, it is the only safety net)
In this particolar case, the code was just an example, but all the logic can be easily wrapped in a single bas module.
Create a new bas module, and cut and paste this code into it:
Code:
Option Explicit
Private Const CB_SHOWDROPDOWN = &H14F
Private Const CB_GETITEMHEIGHT = &H154
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, _
ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function ScreenToClient Lib "user32" _
(ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Public Sub SetComboMenu(frx As Form, cb As ComboBox, ByVal numItemsToDisplay As Long)
Dim pt As POINTAPI
Dim rc As RECT
Dim cWidth As Long
Dim newHeight As Long
Dim oldScaleMode As Long
Dim itemHeight As Long
If numItemsToDisplay > cb.ListCount Then
numItemsToDisplay = cb.ListCount
End If
oldScaleMode = frx.ScaleMode
frx.ScaleMode = vbPixels
cWidth = cb.Width
itemHeight = SendMessage(cb.hWnd, CB_GETITEMHEIGHT, 0, ByVal 0)
newHeight = itemHeight * (numItemsToDisplay + 2)
Call GetWindowRect(cb.hWnd, rc)
pt.x = rc.Left
pt.y = rc.Top
Call ScreenToClient(frx.hWnd, pt)
Call MoveWindow(cb.hWnd, pt.x, pt.y, cb.Width, newHeight, True)
' Call SendMessage(cb.hWnd, CB_SHOWDROPDOWN, True, ByVal 0)
frx.ScaleMode = oldScaleMode
End Sub
that is basically the same code of the article, without the comments, and alla parameters are passed to a single method
In your form load event, you just have to add:
SetComboMenu Me, Combo1, 32
SetComboMenu Me, Combo2, 32
SetComboMenu Me, Combo3, 32
where 32 is the maximum of items displayd in the menu (you can change it as you wish)
NOW, they are really not many lines of code...