Code Samples for Businesses, Schools & Developers

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 Function InputBoxPZ( _
ByVal prompt As String, _
Optional ByVal title As String = vbNullString, _
Optional ByVal Default As String = vbNullString, _
Optional ByVal XPos As Variant, _
Optional ByVal YPos As Variant, _
Optional ByVal HelpFile As String = vbNullString, _
Optional ByVal Context As Long = 0, _
Optional ByVal Zoom As Single = 100!) As String

If title = vbNullString Then
title = Application.Name
End If
m_TargetdialogTitle = title
m_PromptText = prompt
m_IsInputBox = True
m_MsgBoxIconStyle = 0
m_hCustomIcon = 0
m_hPromptEdit = 0
m_IsHeightClamped = False

' Parse zoom percentage (Single value, clamped between MIN_ZOOM_PERCENT and MAX_ZOOM_PERCENT)
Dim safeZoomPercent As Single
safeZoomPercent = ParseZoom(Zoom)
m_ZoomFactor = CDbl(safeZoomPercent) / 100#

' Coordinate setup (Twips to Pixels with display DPI awareness)
Dim hasCustomCoords As Boolean
hasCustomCoords = False

If Not IsMissing(XPos) And Not IsMissing(YPos) Then
If IsNumeric(XPos) And IsNumeric(YPos) Then
If CLng(XPos) >= 0 And CLng(YPos) >= 0 Then
Dim twipsPerPixelX As Double, twipsPerPixelY As Double
CalculateTwipsPerPixel twipsPerPixelX, twipsPerPixelY
m_TargetPixelX = CLng(CDbl(XPos) / twipsPerPixelX)
m_TargetPixelY = CLng(CDbl(YPos) / twipsPerPixelY)
hasCustomCoords = True
End If
End If
End If

If Not hasCustomCoords Then
m_TargetPixelX = -1
m_TargetPixelY = -1
End If

m_TimerElapsedTicks = 0
m_PrevWndProc = 0
m_hScaledFont = 0
m_SubclassedHwnd = 0
m_SplitPixelY = 0

' Always activate timer to ensure height bounds clamping occurs
m_TimerHandle = SetTimer(0, TIMER_IDENTIFIER, 10, AddressOf dialogTimerProc)

' Invoke native InputBox dialog
If Len(HelpFile) > 0 Then
InputBoxPZ = InputBox(prompt, title, Default, , , HelpFile, Context)
Else
InputBoxPZ = InputBox(prompt, title, Default)
End If

' Comprehensive cleanup of resources
CleanupHookResources
End 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

InputBox - Centred, 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

InputBox - Centred, 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

InputBox - Custom Position, 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

InputBox - Top Left, 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

InputBox - Bottom Right, 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.

InputBox - Long text & vertical scrollbar, 125% zoom
      The code used here depends on a function:

' ==============================================================================
' PUBLIC FUNCTION: TestInputBoxLongTextDemo
' Standardised test harness routine for the long multiline scrollable InputBox demonstration.
' ==============================================================================
Public Function TestInputBoxLongTextDemo(Optional ByVal Zoom As Variant = 100) As String
Dim promptText As String, titleText As String, defaultText As String
Dim i As Long

promptText = "DATABASE CONFIGURATION & MIGRATION INSTRUCTIONS:" & vbCrLf & _
"-----------------------------------------------" & vbCrLf
For i = 1 To 30
promptText = promptText & "Step " & Format$(i, "00") & ": Verify schema integrity for partition #" & (500 + i) & _
" and review audit requirements." & vbCrLf
Next i
promptText = 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.

Main Form
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:

MainForm on 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 Function InputBox( _
ByVal prompt As String, _
Optional ByVal title As String = vbNullString, _
Optional ByVal Default As String = vbNullString, _
Optional ByVal XPos As Variant, _
Optional ByVal YPos As Variant, _
Optional ByVal HelpFile As String = vbNullString, _
Optional ByVal Context As Long = 0, _
Optional ByVal Zoom As Single = 100!) As String

If title = vbNullString Then
title = Application.Name
End If
m_TargetdialogTitle = title
m_PromptText = prompt
m_IsInputBox = True
m_MsgBoxIconStyle = 0
m_hCustomIcon = 0
m_hPromptEdit = 0
m_IsHeightClamped = False

' Parse zoom percentage (Single value, clamped between MIN_ZOOM_PERCENT and MAX_ZOOM_PERCENT)
Dim safeZoomPercent As Single
safeZoomPercent = ParseZoom(Zoom)
m_ZoomFactor = CDbl(safeZoomPercent) / 100#

' Coordinate setup (Twips to Pixels with display DPI awareness)
Dim hasCustomCoords As Boolean
hasCustomCoords = False

If Not IsMissing(XPos) And Not IsMissing(YPos) Then
If IsNumeric(XPos) And IsNumeric(YPos) Then
If CLng(XPos) >= 0 And CLng(YPos) >= 0 Then
Dim twipsPerPixelX As Double, twipsPerPixelY As Double
CalculateTwipsPerPixel twipsPerPixelX, twipsPerPixelY
m_TargetPixelX = CLng(CDbl(XPos) / twipsPerPixelX)
m_TargetPixelY = CLng(CDbl(YPos) / twipsPerPixelY)
hasCustomCoords = True
End If
End If
End If

If Not hasCustomCoords Then
m_TargetPixelX = -1
m_TargetPixelY = -1
End If

m_TimerElapsedTicks = 0
m_PrevWndProc = 0
m_hScaledFont = 0
m_SubclassedHwnd = 0
m_SplitPixelY = 0

' Always activate timer to ensure height bounds clamping occurs
m_TimerHandle = SetTimer(0, TIMER_IDENTIFIER, 10, AddressOf dialogTimerProc)

' Invoke native InputBox dialog
If Len(HelpFile) > 0 Then
InputBox = VBA.InputBox(prompt, title, Default, , , HelpFile, Context)
Else
InputBox = VBA.InputBox(prompt, title, Default)
End If

' Comprehensive cleanup of resources
CleanupHookResources
End 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