Form Position Option

N

NevilleT

This shouldn't be so hard. So far I have been struggling for a day on it. I
want to provide an option to users to position a forms in either the top left
hand corner of their Access Window or in the centre of their Access window.
The users can make a selection on their switchboard depending on the screen
resolution they are using. For example, on 1280 x 1024 the screen would be
in the middle of their Access window. on a lower resolution - 1024 x 768 or
even 800 x 600 it is in the top left. Scrolling may be required to see the
whole screen on the rare monitor that is 800 x 600 .

To position at the top left is simple.
DoCmd.MoveSize 0, 0

To make this work the AutoCenter property needs to be set to No. I can only
reset AutoCentre to Yes in design mode. For this reason I cannot change the
AutoCenter property using VBA if the user selects "Form Centred".

I thought that since I know the form size in cms or twips, if I can
calculate the size of the Access Window, I can calculate where to position
the form using MoveSize. There is still the issue of regional settings as I
see MoveSize help tells me.
"Each measurement is in inches or centimeters, depending on the regional
settings in Windows Control Panel."

So far I have been Googleing the issue for hours and playing with pixels to
twips conversion (unsuccessfully). Stephen Lebans has a lot of related
information but I have not been able to pull the threads together. Can
anyone point me in the right direction? Maybe it is all just too hard and I
should forget it.
 
K

Klatuu

There are 1440 twips per inch, but being one of those damn yanks, I know
nothing of cm. But, I do know how to calculate furlongs per fortnight :)
 
D

Dirk Goldgar

NevilleT said:
This shouldn't be so hard. So far I have been struggling for a day on it.
I
want to provide an option to users to position a forms in either the top
left
hand corner of their Access Window or in the centre of their Access
window.
The users can make a selection on their switchboard depending on the
screen
resolution they are using. For example, on 1280 x 1024 the screen would
be
in the middle of their Access window. on a lower resolution - 1024 x 768
or
even 800 x 600 it is in the top left. Scrolling may be required to see
the
whole screen on the rare monitor that is 800 x 600 .

To position at the top left is simple.
DoCmd.MoveSize 0, 0

To make this work the AutoCenter property needs to be set to No. I can
only
reset AutoCentre to Yes in design mode. For this reason I cannot change
the
AutoCenter property using VBA if the user selects "Form Centred".

I thought that since I know the form size in cms or twips, if I can
calculate the size of the Access Window, I can calculate where to position
the form using MoveSize. There is still the issue of regional settings as
I
see MoveSize help tells me.
"Each measurement is in inches or centimeters, depending on the regional
settings in Windows Control Panel."

So far I have been Googleing the issue for hours and playing with pixels
to
twips conversion (unsuccessfully). Stephen Lebans has a lot of related
information but I have not been able to pull the threads together. Can
anyone point me in the right direction? Maybe it is all just too hard and
I
should forget it.


I have used Nicole Calinoiu's clFormWindow class to do this sort of thing.
It makes it quite easy.

http://www.mvps.org/access/forms/frm0042.htm
Forms: Move and Resize form windows from code
 
N

NevilleT

Hi Dirk

Thanks for your quick reply. I am a bit out of my depth here with classes.
I suspect I can get it to work without necessarily understanding it all. I
went to the site, cut and pasted the code into a module and called the module
clFormWindow. Did a compile to see if it was OK and came up with an error

"A module is not a valid type" on the line
Public Property Get Parent() As clFormWindow
 
D

Dirk Goldgar

NevilleT said:
Hi Dirk

Thanks for your quick reply. I am a bit out of my depth here with
classes.
I suspect I can get it to work without necessarily understanding it all.
I
went to the site, cut and pasted the code into a module and called the
module
clFormWindow. Did a compile to see if it was OK and came up with an error

"A module is not a valid type" on the line
Public Property Get Parent() As clFormWindow


That's because you saved it as a standard module, not a class module.
Delete that module, then in Access, click Insert -> Class Module, paste the
code into the new class module that will be created, and save the module as
"clFormWindow".
 
N

NevilleT

Thank you, thank you, thank you!!! It was so easy after you put me onto this
class module. Just to complete the post, after inserting the class module, I
created code in a module as below.

' Center or Top Left
If Forms!frmTitlePage!chkCentre = True Then
DoCmd.MoveSize 0, 0
Else
subFormCentre (strFormName)
End If

frmTitlePage is the switchboard and chkCentre is a checkbox they tick to
place a form at the top left hand corner. subFormCentre is:

Public Sub subFormCentre(ByVal strFormName As String)
Dim fwForm As New clFormWindow
Const SMALL_OFFSET = 5 'Used to position window slightly away from the
Access MDI window border _
in order to avoid appearance of the Access window
vertical scroll bar.
On Error GoTo Error_subFormCentre

With fwForm
.hWnd = Forms(strFormName).hWnd
.Top = (.Parent.Height - .Height) / 2
.Left = (.Parent.Width - .Width - SMALL_OFFSET) / 2
End With

Set fwForm = Nothing

Exit_subFormCentre:
On Error GoTo 0
Exit Sub

Error_subFormCentre:
MsgBox "An unexpected situation arose in your program." & funCrLf & _
"Please write down the following details:" & funCrLf & funCrLf & _
"Module Name: modPACommon" & funCrLf & _
"Type: Module" & funCrLf & _
"Calling Procedure: subFormCentre" & funCrLf & _
"Error Number: " & Err.Number & funCrLf & _
"Error Descritption: " & Err.Description

Resume Exit_subFormCentre

End Sub

Thanks again Dirk. That hurdle took me about a day and a half to get over.
 

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