Solved

Remember Form Screen Position

Posted on 2004-09-09
13
373 Views
Last Modified: 2008-03-17
Good afternoon all,

I am using Access2003.  I have a form with the 'Pop Up" value set to true.  When the form is closed, the next time it is opened I want it to open in the same position it was in when it was closed.

Currently the Form will open depending on where it was saved in design view.  If I move the form, close it and then open it again it opens in the original location not where it was last moved to.

Looking forward to your responses.

Mavreich


0
Comment
Question by:Mavreich
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 34

Expert Comment

by:flavo
Comment Utility
Add this to the forms code

Private Sub Form_Close()
DoCmd.Save acForm, Me.Name
End Sub

Dave
0
 
LVL 2

Author Comment

by:Mavreich
Comment Utility
Hi Flavo,

Thankyou for your speedy response.  It is much appreciated.

Your suggestion does not work for my scenario.  The form does not allow edits, adds or deletions.  It displays a treeview contol for display purposes.  

Thanking you again,  I look forward to an outcome..

Regards
Mavreich
0
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
Comment Utility
Hello Mavreich,

What you ask sounds so reasonable doesn't it. It should be simple!

Look here:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;143162


Pete
0
 
LVL 27

Expert Comment

by:jjafferr
Comment Utility
Hi Mavreich,

Maybe on close you can save the Left and the Top positions in a Table,
then On open of the Form, retrieve these values and apply them.

I hope this helps.

jaffer
0
 
LVL 2

Author Comment

by:Mavreich
Comment Utility
Hi Pete,

Thanks for your response and the pointer.  It is appreciated.  I will look at it over the weekend  :(.

Regards
Mavreich
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility

try this

Private Sub Form_Load()

'DoCmd.MoveSize Right, Down, Width, Height

'example
           DoCmd.MoveSize 4000, 3000            'this will move the 3" x 5 " form at the center of 21 inch monitor


end sub
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 77

Expert Comment

by:peter57r
Comment Utility
Hi Capricorn1,
The issue is not how to set the position but how to FIND the position.

JJafferr
There are no Top and Left properties for a form (or any other positional properties)
It would be a piece of cake if there were.

Pete
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
peter57r,
i need more coffee!!!  zzzzz

rey;-)
0
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
Why?
Isn't life so much better when it's all fuzzy?

Pete
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
I think it depends in the situation you are in.
Sometimes it makes life more exciting.

rey;-)
0
 
LVL 2

Author Comment

by:Mavreich
Comment Utility
Hi all,

I never fails to amaze me how great this forum is.  I really appreciate all the help.  You would think that for such a simple thing as remember form position that there would be a simple solution.  Alas this appears not to be so.

If there is a solution I look forward to it.  In the mean time I am going to allow the user to minimise the form.  Not the solution I want but good enough as a stop gap measure.

I am still investigating the link supplied by pete.

Regards
Mavreich
0
 
LVL 27

Expert Comment

by:jjafferr
Comment Utility
Peter, this is copied from http://www.mvps.org/access/forms/frm0042.htm

 Forms: Move and Resize form windows from code
 Author(s)
Nicole Calinoiu
 
 
   Often times, it's necessary to open forms in specified locations and size them to a custom size. Windows API are the most convenient way of doing this, but the converting between the different coordinate systems can be a pain.

      Download clFormWindows.Bas

    This Class Module hides the API functions and provides generic methods to move and size your forms. The class, once imported in your application, can be used in in a couple of ways.

    1. To align the tops of two forms (at the position of the topmost form):

'********** Code Start ************
Public Sub AlignTops(ByRef frmA As Form, ByRef frmB As Form)
  Dim fwA As New clFormWindow, fwB As New clFormWindow
  fwA.hwnd = frmA.hwnd
  fwB.hwnd = frmB.hwnd
  If fwA.Top < fwB.Top Then
    fwB.Top = fwA.Top
  Else
    fwA.Top = fwB.Top
  End If
 
  Set fwA = Nothing
  Set fwB = Nothing
End Sub
'********** Code End  ************
    2. To move a form to the top right corner of the Access window:

'********** Code Start ************
Public Sub MoveToTopRight(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.
  With fwForm
    .hwnd = Forms(strFormName).hwnd
    .Top = .Parent.Top
    .Left = .Parent.Width - .Width - SMALL_OFFSET
  End With
  Set fwForm = Nothing
End Sub
'********** Code End ************
 
So I guess playing with this code would get the position wanted,
and On Close of the Form,
we have to save the position, Right?
0
 
LVL 2

Author Comment

by:Mavreich
Comment Utility
Hi all,

Thankyou all for your responses.  As always it is appreciated.  I have in the end abandoned this idea of saving the forms screen position.  However as Pete's linkwas the one I spent the most time on I have awared the points to Pete.

If this does not suit those of you who alos gave your valuable help please let me know.

Thanks again.

Mavreich
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now