Screen Dimensions

D

David Pedley

How do I find the current display's dimensions from VBA?

I am writing an Access project (XP/WinXP) and wish to be
able to position forms other than centrally on the screen.

Thanks,

David
 
K

Ken Macksey

Hi

Try this code I found on this NG. I don't know who the original author is.


in the general area, put
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As
Long) As Long
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1


Public Function GSR() As String
GSR = CStr(GetSystemMetrics(SM_CXSCREEN)) & "x" &
CStr(GetSystemMetrics(SM_CYSCREEN))
End Function



Private Sub CommandButton1_Click()

resolution = GSR
MsgBox (resolution)

End Sub

HTH

Ken
 
M

Martin Seelhofer

Hi David

Here's some code to do just that:

Private Declare Function GetSystemMetrics Lib "user32" (ByVal _
nIndex As Long) As Long

Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Function getScreenX()
getScreenX = GetSystemMetrics(SM_CXSCREEN)
End Function

Function getScreenY()
getScreenY = GetSystemMetrics(SM_CYSCREEN)
End Function

NB: These values are pixel-values. Remember that forms work with TWIPS
instead!


Cheers,

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top