O
OssieMac
Access 2002 with all updates.
I have the following code to identify the position parameters for forms so
that I can use the parameters in the Form_Open events as per the following
example:
Me.Move Left:=4050, Top:=200, Width:=11085, Height:=8715
I open the forms and position and size them and then run the code from the
VBA Editor.
The code works perfectley when called from either of the following two subs:
Sub Call_Position_Option_1()
and from:
Sub Call_Position_Option_2()
However when called from Sub Call_Position_Option_3()
I get an error at the msgbox in
Sub Position_Params(objFormId As Object)
Error is Run-time error '438'
Object doesn't support this property or method
What am I not understanding or missing here? I thought that it should work
from all three calling subs.
I realize that I have code that works but my curiosity has got the better of
me and I would like to understand what the problem is.
If I delete the position parameters and the msgbox is:
MsgBox "Form Name: " & .Name
then it returns the form name OK so it is the position parameters that cause
it to fail.
All help is greatly appreciated.
Sub Call_Position_Option_1()
Dim objForm As Object
Dim i As Integer
'Forms.Count returns only Loaded forms
For i = 0 To Forms.Count - 1
Set objForm = Forms(i)
Call Position_Params(objForm)
Next i
End Sub
Sub Call_Position_Option_2()
Dim objForm As Object
'For Each objForm In Forms returns only loaded forms
For Each objForm In Forms
Call Position_Params(objForm)
Next objForm
End Sub
Sub Call_Position_Option_3()
Dim dbs As Object
Dim objForm As Object
Set dbs = Application.CurrentProject
'For Each objForm In dbs.AllForms _
returns all forms (Loaded and Not Loaded) _
so test for IsLoaded
For Each objForm In dbs.AllForms
If objForm.IsLoaded = True Then
Call Position_Params(objForm)
End If
Next objForm
End Sub
Sub Position_Params(objFormId As Object)
'Called sub which requires parameter
'The following line of code returns the error when _
called from Sub Call_Form_Pos_Params_3
With objFormId
MsgBox "Form Name: " & .Name & Chr(13) & _
"WindowLeft: " & .WindowLeft & Chr(13) & _
"WindowTop: " & .WindowTop & Chr(13) & _
"WindowWidth: " & .WindowWidth & Chr(13) & _
"WindowHeight: " & .WindowHeight
End With
End Sub
I have the following code to identify the position parameters for forms so
that I can use the parameters in the Form_Open events as per the following
example:
Me.Move Left:=4050, Top:=200, Width:=11085, Height:=8715
I open the forms and position and size them and then run the code from the
VBA Editor.
The code works perfectley when called from either of the following two subs:
Sub Call_Position_Option_1()
and from:
Sub Call_Position_Option_2()
However when called from Sub Call_Position_Option_3()
I get an error at the msgbox in
Sub Position_Params(objFormId As Object)
Error is Run-time error '438'
Object doesn't support this property or method
What am I not understanding or missing here? I thought that it should work
from all three calling subs.
I realize that I have code that works but my curiosity has got the better of
me and I would like to understand what the problem is.
If I delete the position parameters and the msgbox is:
MsgBox "Form Name: " & .Name
then it returns the form name OK so it is the position parameters that cause
it to fail.
All help is greatly appreciated.
Sub Call_Position_Option_1()
Dim objForm As Object
Dim i As Integer
'Forms.Count returns only Loaded forms
For i = 0 To Forms.Count - 1
Set objForm = Forms(i)
Call Position_Params(objForm)
Next i
End Sub
Sub Call_Position_Option_2()
Dim objForm As Object
'For Each objForm In Forms returns only loaded forms
For Each objForm In Forms
Call Position_Params(objForm)
Next objForm
End Sub
Sub Call_Position_Option_3()
Dim dbs As Object
Dim objForm As Object
Set dbs = Application.CurrentProject
'For Each objForm In dbs.AllForms _
returns all forms (Loaded and Not Loaded) _
so test for IsLoaded
For Each objForm In dbs.AllForms
If objForm.IsLoaded = True Then
Call Position_Params(objForm)
End If
Next objForm
End Sub
Sub Position_Params(objFormId As Object)
'Called sub which requires parameter
'The following line of code returns the error when _
called from Sub Call_Form_Pos_Params_3
With objFormId
MsgBox "Form Name: " & .Name & Chr(13) & _
"WindowLeft: " & .WindowLeft & Chr(13) & _
"WindowTop: " & .WindowTop & Chr(13) & _
"WindowWidth: " & .WindowWidth & Chr(13) & _
"WindowHeight: " & .WindowHeight
End With
End Sub