'************************************** ' Name: FormWinRegPos ' Description:This Procedure can be used ' by AnyForm to Get or Save the Form Posit ' ion from the Windows Registry using Save ' Setting and GetSetting :) ' By: Brad Skidmore (from psc cd) ' ' ' Inputs:pMyForm As Form Optional pbSave As Boolean ' ' Returns:None ' 'Assumes:Best to use this in either Form ' _Load, Form_Unload or Form_QueryUnload Form_Load For Getting the Saved Form Posn Settings Unload or QueryUnload for saveing Current Form Posn. ' 'Side Effects:None '************************************** Option Explicit Public Sub FormWinRegPos(pMyForm As Form, Optional pbSave As Boolean) 'This Procedure will Either Retrieve or ' Save Form Posn values 'Best used on Form Load and Unload or Qu ' eryUnLoad On Error GoTo EH With pMyForm If pbSave Then 'If Saving then do this... 'If Form was minimized or Maximized then ' Closed Need to Save Windowstate 'THEN... set Back to Normal Or previous ' non Max or Min State then Save 'Posn Parameters SaveSetting App.EXEName ' , .Name, "Top", .Top SaveSetting App.EXEName, .Name, "WindowState", .WindowState If .WindowState = vbMinimized Or .WindowState = vbMaximized Then .WindowState = vbNormal End If 'Save AppName...FrmName...KeyName...Valu ' e SaveSetting App.EXEName, .Name, "Top", .Top SaveSetting App.EXEName, .Name, "Left", .Left SaveSetting App.EXEName, .Name, "Height", .Height SaveSetting App.EXEName, .Name, "Width", .Width Else 'If Not Saveing Must Be Getting .. 'Need to ref AppName...FrmName...KeyName ' (If nothing Stored Use The Exisiting For ' m value) .Top = GetSetting(App.EXEName, .Name, "Top", .Top) .Left = GetSetting(App.EXEName, .Name, "Left", .Left) .Height = GetSetting(App.EXEName, Name, "Height", .Height) .Width = GetSetting(App.EXEName, .Name, "Width", .Width) 'Be Sure WindowState is set last (Can't ' Change POSN if vbMinimized Or Maximized .WindowState = GetSetting(App.EXEName, .Name, "WindowState", .WindowState) End If End With Exit Sub EH: MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description End Sub Private Sub Form_Load() FormWinRegPos Me End Sub Private Sub Form_Unload(Cancel As Integer) FormWinRegPos Me, True End Sub