| Version 1.2 Approx 0.8 MB (zipped) | First Published 2 Nov 2026 |
|---|
This is a companion to my recent article: Message Box with Position & Zoom
Like the standard VBA message box, input boxes have small font size (8pt) and cannot be zoomed (other than by using Windows scaling).
However, unlike the standard VBA message box, the position of input boxes can be specified. By default they are always centred on the screen.
With modern monitors and typical resolutions of 1920 x 1080 or higher, the small text can be difficult to read comfortably, even for users whose eyesight is reasonably good.
The default centred positioning can also mean that users often need to move the input box to one side before entering a value.
The InputBoxPZ (position/zoom) function allows developers/users to both control where a input box opens and to adjust its zoom level.
This project was started by my colleague Xevi Batlle with the assistance of Gemini/Antigravity AI.
I then further modified the functionality to allow the input box to be docked to specific positions on the screen.
The InputBoxPZ function
To allow input boxes to be zoomed, the InputBoxPZ function adds an extra optional Zoom argument to the default VBA InputBox function:
Syntax: Items in [ ] are optional
InputBoxPZ (Prompt, [Title], [Default], [XPos], [YPos], [HelpFile], [Context], [Zoom])
The optional Zoom argument has a default value = 100 (%) with the allowed percentage zoom range from 50 to 1000
The full InputBoxPZ function code is:
' ==============================================================================' PUBLIC FUNCTION: InputBoxPZ' ==============================================================================Public FunctionInputBoxPZ( _ByValpromptAs String, _Optional ByValtitleAs String=vbNullString, _Optional ByValDefaultAs String=vbNullString, _Optional ByValXPosAs Variant, _Optional ByValYPosAs Variant, _Optional ByValHelpFileAs String=vbNullString, _Optional ByValContextAs Long= 0, _Optional ByValZoomAs Single= 100!)As StringIftitle=vbNullStringThentitle=Application.NameEnd Ifm_TargetdialogTitle=titlem_PromptText=promptm_IsInputBox=Truem_MsgBoxIconStyle= 0m_hCustomIcon= 0m_hPromptEdit= 0m_IsHeightClamped=False' Parse zoom percentage (Single value, clamped between MIN_ZOOM_PERCENT and MAX_ZOOM_PERCENT)DimsafeZoomPercentAs SinglesafeZoomPercent=ParseZoom(Zoom)m_ZoomFactor=CDbl(safeZoomPercent) / 100#' Coordinate setup (Twips to Pixels with display DPI awareness)DimhasCustomCoordsAs BooleanhasCustomCoords=FalseIf NotIsMissing(XPos)And NotIsMissing(YPos)ThenIfIsNumeric(XPos)AndIsNumeric(YPos)ThenIf CLng(XPos) >= 0And CLng(YPos) >= 0ThenDimtwipsPerPixelXAs Double,twipsPerPixelYAs DoubleCalculateTwipsPerPixel twipsPerPixelX,twipsPerPixelYm_TargetPixelX=CLng(CDbl(XPos) /twipsPerPixelX)m_TargetPixelY=CLng(CDbl(YPos) /twipsPerPixelY)hasCustomCoords=TrueEnd IfEnd IfEnd IfIf NothasCustomCoordsThenm_TargetPixelX= -1m_TargetPixelY= -1End Ifm_TimerElapsedTicks= 0m_PrevWndProc= 0m_hScaledFont= 0m_SubclassedHwnd= 0m_SplitPixelY= 0' Always activate timer to ensure height bounds clamping occursm_TimerHandle=SetTimer(0,TIMER_IDENTIFIER, 10,AddressOfdialogTimerProc)' Invoke native InputBox dialogIfLen(HelpFile) > 0ThenInputBoxPZ=InputBox(prompt,title,Default, , ,HelpFile,Context)ElseInputBoxPZ=InputBox(prompt,title,Default)End If' Comprehensive cleanup of resourcesCleanupHookResourcesEnd Function
The standard InputBox function is an integral part of VBA and incorporating this additional functionality required a very large number of APIs, types and constants.
It also depends on a large number of support procedures:
• CleanupHookResources
• ParseZoom
• dialogTimerProc
• HasEditControl
• GetdialogWorkArea
• GetFontLineHeight
• ApplyZoomAndPosition
• InitialiseScaledFont
• GetStockIconIdentifier
• ExtractModernStockIcon
• IsButtonControl
• IsEditControl
• IsPromptTextControl
• CalculateTextHeight
• ScaleInputBoxControls
• dialogSubclassProc
• PaintCustomBackground
• CalculateTwipsPerPixel
The full code is in the module modCustomInputBox. To say that the code is complex would be an understatement and I have no intention of explaining each part of it in this article.
NOTE: As almost all of these functions are also used in the MsgBoxPZ function, I have kept both sets of code in the modCustomInputBox module.
Additional code is used to manage the docking of messages to specific corners of the screen. This is in the modules modMetrics and modMonitorInfo.
Although much of the code is complex, using it in your own applications is extremely easy! For example:
a) Replicate a standard input box centred on the screen at default 100% zoom
InputBoxPZ "Zoom =" & zoomPercent & "%" & vbCrLf & vbCrLf & "Please enter your project identifier:", _
"Centred Input Box with Zoom = 100", "Default input", , , , , 100
OR omitting the default values . . .
InputBoxPZ "Zoom =" & zoomPercent & "%" & vbCrLf & vbCrLf & "Please enter your project identifier:" _
"Centred Input Box with Zoom = 100", "Default input"
b) Input box centred on the screen at 175% zoom
InputBoxPZ "Zoom =" & zoomPercent & "%" & vbCrLf & vbCrLf & "Please enter your project identifier:" _
"Centred Input Box with Zoom = 175", "Default input", , , , , 175
OR using named Zoom argument . . .
InputBoxPZ "Zoom =" & zoomPercent & "%" & vbCrLf & vbCrLf & "Please enter your project identifier:" _
"Centred Input Box with Zoom = 175", "Default input", Zoom:= 175
c) Place an input box at Left = 3000, Top = 1500 (both in twips) and 125% zoom
InputBoxPZ "Custom input box zoom demonstration with scaled buttons and font." & vbCrLf & vbCrLf & _
"Left = 3000, Top = 1500 (twips)" & vbCrLf & "Zoom = 125%" _
"Custom Input Box with Zoom = 125", "Default input", XPos:= 3000, YPos:= 1500, Zoom:= 125
d) Position an input box at top left corner: Left = 0, Top = 0 and 150% zoom
InputBoxPZ "This input box is located near the top-left corner." & vbCrLf & vbCrLf & "Zoom = 150%", "Top-Left Corner with Zoom = 150", _
"Default input", XPos:= 0, YPos:= 0, Zoom:= 150
e) Position an input box at bottom right corner with 200% zoom
'get screen height and width to determine bottom right corner position
Dim MSH As Long, MSW As Long
MSH = MetricsScreenHeight()
MSW = MetricsScreenWidth()
InputBoxPZ "This dialog box is located near the bottom-right corner." & vbCrLf & vbCrLf & "Zoom = 200%", "Bottom-Right Corner with Zoom = 200", _
"Default input", XPos:= MSW, YPos:= MSH, Zoom:= 200
f) Input box with long text and vertical scrollbar
The InputBoxPZ function also provides a vertical scrollbar where the text is too long to fit in the dialog box.
The code used here depends on a function:
' ==============================================================================' PUBLIC FUNCTION: TestInputBoxLongTextDemo' Standardised test harness routine for the long multiline scrollable InputBox demonstration.' ==============================================================================Public FunctionTestInputBoxLongTextDemo(Optional ByValZoomAs Variant= 100)As StringDimpromptTextAs String,titleTextAs String,defaultTextAs StringDimiAs LongpromptText= "DATABASE CONFIGURATION & MIGRATION INSTRUCTIONS:"&vbCrLf& _"-----------------------------------------------"&vbCrLfFori= 1To30promptText=promptText& "Step "&Format$(i, "00") & ": Verify schema integrity for partition #"& (500 +i) & _" and review audit requirements."&vbCrLfNextipromptText=promptText&vbCrLf& _"Please enter confirmation authorisation key to proceed:"titleText= "InputBox Long Text & Scrollbar Demonstration: (Zoom = "&Zoom& ")"defaultText= "AUTH-KEY-9988"TestInputBoxLongTextDemo=InputBoxPZ(promptText,titleText,defaultText,Zoom:=CSng(Zoom))End Function
Example Usage: TestInputBoxLongTextDemo 125
Example App
The example app supplied with this article has a single form that allows you to test the functionality.
NOTE: The positioning code only works reliably on the primary monitor. For that reason, several buttons are automatically disabled when Access is on a secondary monitor:
Download
Click to download: InputBoxPositionZoom_v1.2 ACCDB file - approx 0.8 MB (zipped)
As is the case for all files downloaded from the internet, first unblock the downloaded file, unzip then save to a trusted location.
For more details, see my article:
Unblock downloaded files by removing the Mark of the Web
Using the InputBoxPZ function in your own apps
To use this function in your own apps, import the module modCustomInputBox.
If you also want to make use of the docking functionality, also import the modules modMetrics and modMonitorInfo.
OPTIONAL: Rename the InputBoxPZ function as MsgBox. Access will then use this custom function in place of the standard VBA InputBox function.
Doing this will require minor alterations to the existing function code shown above (and that used in the example app) to disambiguate the references to the VBA InputBox function.
The updated code is as follows:
' ==============================================================================' PUBLIC FUNCTION: InputBox replacement' ENABLE this function if you want to replace the built-in VBA InputBox function' ==============================================================================Public FunctionInputBox( _ByValpromptAs String, _Optional ByValtitleAs String=vbNullString, _Optional ByValDefaultAs String=vbNullString, _Optional ByValXPosAs Variant, _Optional ByValYPosAs Variant, _Optional ByValHelpFileAs String=vbNullString, _Optional ByValContextAs Long= 0, _Optional ByValZoomAs Single= 100!)As StringIftitle=vbNullStringThentitle=Application.NameEnd Ifm_TargetdialogTitle=titlem_PromptText=promptm_IsInputBox=Truem_MsgBoxIconStyle= 0m_hCustomIcon= 0m_hPromptEdit= 0m_IsHeightClamped=False' Parse zoom percentage (Single value, clamped between MIN_ZOOM_PERCENT and MAX_ZOOM_PERCENT)DimsafeZoomPercentAs SinglesafeZoomPercent=ParseZoom(Zoom)m_ZoomFactor=CDbl(safeZoomPercent) / 100#' Coordinate setup (Twips to Pixels with display DPI awareness)DimhasCustomCoordsAs BooleanhasCustomCoords=FalseIf NotIsMissing(XPos)And NotIsMissing(YPos)ThenIfIsNumeric(XPos)AndIsNumeric(YPos)ThenIf CLng(XPos) >= 0And CLng(YPos) >= 0ThenDimtwipsPerPixelXAs Double,twipsPerPixelYAs DoubleCalculateTwipsPerPixel twipsPerPixelX,twipsPerPixelYm_TargetPixelX=CLng(CDbl(XPos) /twipsPerPixelX)m_TargetPixelY=CLng(CDbl(YPos) /twipsPerPixelY)hasCustomCoords=TrueEnd IfEnd IfEnd IfIf NothasCustomCoordsThenm_TargetPixelX= -1m_TargetPixelY= -1End Ifm_TimerElapsedTicks= 0m_PrevWndProc= 0m_hScaledFont= 0m_SubclassedHwnd= 0m_SplitPixelY= 0' Always activate timer to ensure height bounds clamping occursm_TimerHandle=SetTimer(0,TIMER_IDENTIFIER, 10,AddressOfdialogTimerProc)' Invoke native InputBox dialogIfLen(HelpFile) > 0ThenInputBox=VBA.InputBox(prompt,title,Default, , ,HelpFile,Context)ElseInputBox=VBA.InputBox(prompt,title,Default)End If' Comprehensive cleanup of resourcesCleanupHookResourcesEnd Function
The modified code is supplied with the example app but has been disabled. Enable the function by removing the comments from the code block.
All existing InputBox code will continue to work without any alteration, with those input boxes centred displayed in the specified position at 100% zoom!
Related Article
A very similar function called MsgBoxPZ can be used to enhance/replace the standard MsgBox function by adding the same additional positioning and zoom functionality.
See my article: Message Box with Position & Zoom
Feedback
Please use the Email button in the contact form below to let me know whether you found this article useful or if you have any questions.
Please also consider making a donation towards the costs of maintaining this website. Thank you
| Colin Riddington | Mendip Data Systems | Last Updated 2 Nov 2026 |
|---|
|
Return to Code Samples Page
|
Return to Top
|