jwcolby54
Active member
- Local time
- Yesterday, 23:57
- Joined
- May 19, 2025
- Messages
- 345
Well that works.
First I made the clsOpenArgs up in the form's header public so that I could see it from outside the form.
Of course the correct way to do this is to create a property in the form to expose the clsOpenArgs but this is just test code.
I had not created the method to apply the properties to the form so I did that.
I then created a function out in a test module to get a pointer to that specific form so that I could play around.
I then opened the form as follows (in the debug window):
docmd.OpenForm "frmOpenArgsDemo",acNormal,,,,acWindowNormal,"Visible=false;Color=Blue"
passing in two open args, visible=false and color=blue
I then called the method in the debug window to apply the OpenArgs to the form's properties (in the debug window):
frmOpenArgsDemo.mclsOpenArgs.fApplyFormProperties
The form went invisible due to the first OpenArg. Then the second OpenArg threw an error as shown.
Error 2455 (You entered an expression that has an invalid reference to the property Color.) in procedure EDPDemoDB.clsOpenArgs.fApplyFormProperties, line 0.
So the concept works.
The code is up on GitHub in my demo database. frmOpenArgsDemo for the form, basTest for the module with the code to get a pointer to the open form. It has to be open obviously.
This has been a post to demonstrate a little more about classes
First I made the clsOpenArgs up in the form's header public so that I could see it from outside the form.
Code:
Option Compare Database
Option Explicit
Public mclsOpenArgs As clsOpenArgs
I had not created the method to apply the properties to the form so I did that.
Code:
Function fApplyFormProperties()
On Error GoTo fApplyFormProperties_Error
Dim lclsOpenArg As clsOpenArg
For Each lclsOpenArg In mcolOpenArg
mfrm.Properties(lclsOpenArg.pName) = lclsOpenArg.pVal
Next lclsOpenArg
Exit_fApplyFormProperties:
On Error GoTo 0
Exit Function
fApplyFormProperties_Error:
Dim strErrMsg As String
Select Case Err
Case 0 'insert Errors you wish to ignore here
Resume Next
Case Else 'All other errors will trap
strErrMsg = "Error " & Err.Number & " (" & Err.Description & ") in procedure EDPDemoDB.clsOpenArgs.fApplyFormProperties, line " & Erl & "."
Beep
#If boolELE = 1 Then
WriteErrorLog strErrMsg
#End If
assDebugPrint strErrMsg
Resume Exit_fApplyFormProperties
End Select
Resume Exit_fApplyFormProperties
Resume 0 'FOR TROUBLESHOOTING
End Function
I then created a function out in a test module to get a pointer to that specific form so that I could play around.
Code:
Function frmOpenArgsDemo() As Form_frmOpenArgsDemo
Set frmOpenArgsDemo = Forms("frmOpenArgsDemo")
End Function
I then opened the form as follows (in the debug window):
docmd.OpenForm "frmOpenArgsDemo",acNormal,,,,acWindowNormal,"Visible=false;Color=Blue"
passing in two open args, visible=false and color=blue
I then called the method in the debug window to apply the OpenArgs to the form's properties (in the debug window):
frmOpenArgsDemo.mclsOpenArgs.fApplyFormProperties
The form went invisible due to the first OpenArg. Then the second OpenArg threw an error as shown.
Error 2455 (You entered an expression that has an invalid reference to the property Color.) in procedure EDPDemoDB.clsOpenArgs.fApplyFormProperties, line 0.
So the concept works.
The code is up on GitHub in my demo database. frmOpenArgsDemo for the form, basTest for the module with the code to get a pointer to the open form. It has to be open obviously.
This has been a post to demonstrate a little more about classes