Passing Variable to DoCmd.MoveSize to move Forms

291 Views Asked by At

I'm trying to keep the position of all forms uniform when switching between them all, but when calling the code in a function, MaxSize isn't working.

This records the WindowLeft and WindowTop value in a table, and I run this just before any form closes.

Function recordFormPosition(frm As Form)

On Error GoTo Error
    DoCmd.SetWarnings False

                          'Table           Field          Window position
    DoCmd.RunSQL "UPDATE FormPosition SET FormTop = """ & frm.WindowTop & """"
    DoCmd.RunSQL "UPDATE FormPosition SET FormLeft = """ & frm.WindowLeft & """"
    DoCmd.SetWarnings True
    Exit Function

debug
Error:
MsgBox ("Error")
End Function

This function is called on any Form_Load to set the form to the position recorded in the table

Function setFormPosition(frm As Form)

    Dim db As DAO.Database
    Set db = CurrentDb
    Dim tp As DAO.Recordset
    Dim lft As DAO.Recordset
    Dim wintop As String
    Dim winleft As String

    'Sets location of form
    wintop = "SELECT FormTop FROM FormPosition WHERE ID = 1"
    winleft = "SELECT FormLeft FROM FormPosition WHERE ID = 1"
    
    Set tp = db.OpenRecordset(wintop)
    Set lft = db.OpenRecordset(winleft)
    
    frm.DoCmd.MoveSize tp.Fields(0).Value, lft.Fields(0).Value
    
End Function

And I use this to call the function and pass the form variable

Call setFormPosition([Form])      or     Call recordFormPosition([Form])

My problem is with this line:

DoCmd.MoveSize tp.Fields(0).Value, lft.Fields(0).Value

Where do I pass on the frm. variable? I keep getting the error: An Expression in argument 2 has an invalid value, but I'm passing 2 intergers from a table that is formatted to numbers. I did some debugging and passed tp.Fields(0).Value & lft.Fields(0).Value in msgbox's and can verify that they are returning numbers, so the only explaination is that it has to be a focus issue

0

There are 0 best solutions below