By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,510 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,510 IT Pros & Developers. It's quick & easy.

Centre a VBA Input box

PhilOfWalton
Expert 100+
P: 1,430
I am using the following code to trap an input to an InputBox, translate it to another language, then show the translated Input box.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function InputBox(Prompt As String, Optional Title, Optional Default As String, Optional XPos As Long, Optional YPos As Long, Optional HelpFile, Optional Context) As Variant    ' ** Ignore **
  3.     ' Wrapper for InpuBbox
  4.  
  5.     Dim TranslatedInput As String
  6.     Dim LanguageID As Long
  7.  
  8.     LanguageID = TempVars!RequiredLanguageID
  9.  
  10.     TranslatedInput = TranslateMsgBox(Prompt, LanguageID)
  11.     If Not IsMissing(Default) Then
  12.         If GetFromLanguageID(CStr(Default)) > 0 Then                  ' We may not be able to find the default
  13.             Default = OtherWord(CStr(Default), GetFromLanguageID(CStr(Default)), LanguageID)
  14.         End If
  15.     End If
  16.  
  17.     If Not IsMissing(Title) Then
  18.         If GetFromLanguageID(CStr(Title)) > 0 Then                  ' We may not be able to find the title
  19.             Title = OtherWord(CStr(Title), GetFromLanguageID(CStr(Title)), LanguageID)
  20.         End If
  21.     End If
  22.  
  23.     InputBox = VBA.InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
  24.  
  25. End Function
  26.  
Now with a standard InputBox, if Xpos & Ypos are not defined, the InputBox appears somewhere in the centre of the screen (NOT the Access Window) and about 1/3 the way down

With the above function, if XPos & YPos aren't specified, the input box appears top left of the screen (I assume it regards XPos & YPos = 0)

Is there a simple way of getting the original position (more or less) without using the long complicate routine of getting screen sizes, resolutions etc.

Thanks

Phil
Jan 18 '18 #1
Share this Question
Share on Google+
1 Reply


PhilOfWalton
Expert 100+
P: 1,430
Problem solved (Good night's sleep)

Here is the code in case anyone needs it.

Expand|Select|Wrap|Line Numbers
  1. Function InputBox(Prompt As String, Optional Title, Optional Default, Optional XPos, Optional YPos, Optional HelpFile, Optional Context) As Variant       ' ** Ignore **
  2.     ' Wrapper for InputBbox
  3.     '?inputbox("PLease enter something")
  4.     '?inputbox("PLease enter something","This is a title","Def Val",19000,10000,"Demo.Hlp",0)
  5.  
  6.     Dim TranslatedInput As String
  7.     Dim LanguageID As Long
  8.  
  9.     LanguageID = TempVars!RequiredLanguageID
  10.  
  11.     TranslatedInput = TranslateMsgBox(Prompt, LanguageID)
  12.     If Not IsMissing(Default) Then
  13.         If GetFromLanguageID(CStr(Default)) > 0 Then                  ' We may not be able to find the default
  14.             Default = OtherWord(CStr(Default), GetFromLanguageID(CStr(Default)), LanguageID)
  15.         End If
  16.     End If
  17.  
  18.     ' Both XPos & YPos must be defined to set ite InputBox position, otherwise it centers in the upper portion of the screen
  19.     ' If HelpFile is defined, Context must also have a value
  20.     If Not IsMissing(Title) Then
  21.         If GetFromLanguageID(CStr(Title)) > 0 Then                  ' We may not be able to find the title
  22.             Title = OtherWord(CStr(Title), GetFromLanguageID(CStr(Title)), LanguageID)
  23.         End If
  24.     End If
  25.  
  26.     If Not IsMissing(XPos) And Not IsMissing(YPos) Then
  27.         InputBox = VBA.InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
  28.     Else
  29.         InputBox = VBA.InputBox(Prompt, Title, Default, , , HelpFile, Context)
  30.     End If
  31.  
  32. End Function
  33.  
Phil
Jan 19 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.