I'm kind of a novice at Access and having some difficulty implementing something I saw in another post. MS-Access: How to open form in same location/size as closed/previous form?
I want to open my pop-up forms in the same location they were last closed in and I've created a table (sizpos) to store the 4 attributes for position and size (left, top, width, height) and the name of the form (object) and a unique id number.
I need some help figuring out the VBA code to store the attributes of the open form based on the form name on the close or unload event. I also need help with the code to retrieve the information from the table for the opening form on the open or load event.
I tried making use of dlookup
in me.move
and did not have any success, but may not have been implementing it correctly.
I came up with the following that almost works for the reports. I just can't figure out how to pull the report's name from the report being opened similar to the me.name
function in a form. I've noted those areas with me.reportname
???
Private Sub Report_Open(Cancel As Integer)
Dim l As Long
Dim t As Long
l = Nz(DLookup("Left", "SizPos", "Object = 'me.reportname???'"))
t = Nz(DLookup("Top", "SizPos", "Object = 'me.reportname???'"))
Me.Move Left:=l, Top:=t
End Sub
Private Sub Report_Close()
Dim strSQL As String
strSQL = "UPDATE SizPos SET SizPos.Left = " & Me.WindowLeft & ", SizPos.Top = " & Me.WindowTop & " WHERE SizPos.Object = 'me.reportname???';"
CurrentDb.Execute strSQL
End Sub
The below works great for the form.
Private Sub Form_Open(Cancel As Integer)
Dim l As Long
Dim t As Long
Dim w As Long
Dim h As Long
l = Nz(DLookup("Left", "SizPos", "Object = '" & Me.Name & "'"))
t = Nz(DLookup("Top", "SizPos", "Object = '" & Me.Name & "'"))
w = Nz(DLookup("Width", "SizPos", "Object = '" & Me.Name & "'"))
h = Nz(DLookup("Height", "SizPos", "Object = '" & Me.Name & "'"))
Me.Move Left:=l, Top:=t, Width:=w, Height:=h
End Sub
Private Sub Form_Close()
DoCmd.Save
Dim strSQL As String
strSQL = "UPDATE SizPos SET SizPos.Left = " & Me.WindowLeft & ", SizPos.Top = " & Me.WindowTop & ", SizPos.Width = " & Me.WindowWidth & ", SizPos.Height = " & Me.WindowHeight & " WHERE SizPos.Object = '" & Me.Name & "';"
CurrentDb.Execute strSQL
End Sub
reportname
property. UseMe.Name
to get the report's name.Me.Name
is available both in a form or report. – HansUp