jwcolby54
Active member
- Local time
- Yesterday, 19:39
- Joined
- May 19, 2025
- Messages
- 283
This thread is written solely to teach classes and framework concepts. To quote Paul, and it feels like I have done so waaay too often, there must be 50 ways to leave your lover. If you would like to teach how to use classes, events and frameworks, I encourage you to do so. Just not in this thread please. In the meantime, please refrain from "my way is better for reason xyz". Might be, not the point.
Man I hate doing that!
OpenArgs are a string passed into a form by the opening code. OpenArgs are used in any way that the developer desires to use them.
As an example of how they might be used, in my framework I allow my combo class dbl-click to open a form to edit the data in that combo.

As the form opens I use OpenArgs to pass in the PK of the record displayed in the combo. The form will read the OpenArgs, discover it has an OpenArg similar to "PKID=4" and based on that will seek to the record with PKID=4. This allows an easy way for a user to get at the data behind a combo box. If the data is modified, my clsCtlCbo will requery the combo when the opened form closes, and any changes will appear in the combo box.

That is OpenArgs at work.
The following is the code for OpenArg (singular):
The following is the code for OpenArgs (plural). It is the supervisor. It gets the OpenArgs string if it exists, parses it, and stores any OpenArgs found in a class for each, stored in a collection. It also has a crude method for pushing any OpenArgs into form properties if the OpenArg name matches any form property name. Just a way to set the properties of a form as it opens. YMMV on that one.
Man I hate doing that!
OpenArgs are a string passed into a form by the opening code. OpenArgs are used in any way that the developer desires to use them.
As an example of how they might be used, in my framework I allow my combo class dbl-click to open a form to edit the data in that combo.

As the form opens I use OpenArgs to pass in the PK of the record displayed in the combo. The form will read the OpenArgs, discover it has an OpenArg similar to "PKID=4" and based on that will seek to the record with PKID=4. This allows an easy way for a user to get at the data behind a combo box. If the data is modified, my clsCtlCbo will requery the combo when the opened form closes, and any changes will appear in the combo box.

That is OpenArgs at work.
The following is the code for OpenArg (singular):
Code:
Option Compare Database
Option Explicit
Private mstrArgName As String 'The OpenArg name
Private mvarArgVal As Variant 'The OpenArg value
Private mblnIsProperty As Boolean 'fills a form property
Function fInit(lstrArgName As String, lvarArgVal As Variant)
mstrArgName = lstrArgName
mvarArgVal = lvarArgVal
End Function
Function pName() As String
pName = mstrArgName
End Function
Function pVal() As Variant
pVal = mvarArgVal
End Function
Property Let pIsPrp(lmblnIsProperty As Boolean)
mblnIsProperty = lmblnIsProperty
End Property
Property Get pIsPrp() As Boolean
pIsPrp = mblnIsProperty
End Property
The following is the code for OpenArgs (plural). It is the supervisor. It gets the OpenArgs string if it exists, parses it, and stores any OpenArgs found in a class for each, stored in a collection. It also has a crude method for pushing any OpenArgs into form properties if the OpenArg name matches any form property name. Just a way to set the properties of a form as it opens. YMMV on that one.
Code:
Option Compare Database
Option Explicit
Private mfrm As Form 'A form reference passed in
Private mstrOpenArgs As String
Private mcolOpenArg As Collection
Private mblnApplyProperties As Boolean
Private Sub Class_Initialize()
Set mcolOpenArg = New Collection
End Sub
Private Sub Class_Terminate()
Set mfrm = Nothing
Set mcolOpenArg = Nothing
End Sub
Property Get cOpenArgByName(strName As String) As clsOpenArg
On Error Resume Next
Set cOpenArgByName = mcolOpenArg(strName)
End Property
Property Get colOpenArgs() As Collection
Set colOpenArgs = mcolOpenArg
End Property
Public Sub fInit(lFrm As Form, _
Optional lblnApplyProperties As Boolean = False)
Set mfrm = lFrm
mblnApplyProperties = lblnApplyProperties
'The openargs string might be null
On Error Resume Next
mstrOpenArgs = mfrm.OpenArgs
ParseOpenArgs mstrOpenArgs
'
'The default is false,
'do not try and apply OpenArgs as form properties
'If the deveopler wants to
'They must say so
'
If mblnApplyProperties Then
'ApplyFrmProperties
End If
End Sub
'*+ Public Property interface
Property Get pName() As String
pName = mfrm.Name & ":clsOpenArgs"
End Property
'*- Public Property interface
Private Sub ParseOpenArgs(lStrOpenArgs As String)
Dim lclsOpenArg As clsOpenArg
Dim arrSplitStrings() As String
Dim varStrOpenArg As Variant
arrSplitStrings = Split(lStrOpenArgs, ";")
For Each varStrOpenArg In arrSplitStrings
'
'handle a final ; in varStrOpenArgs if it exists
If Len(varStrOpenArg) > 0 Then
Debug.Print varStrOpenArg
Set lclsOpenArg = cOpenArg(varStrOpenArg)
mcolOpenArg.Add lclsOpenArg, lclsOpenArg.pName
End If
Next varStrOpenArg
End Sub
Private Function cOpenArg(lStrOpenArg As Variant) As clsOpenArg
Dim arrSplitStrings() As String
Dim varOpenArgPart As Variant
Dim strArgName As String
Dim varArgVal As Variant
Dim lclsOpenArg As clsOpenArg
arrSplitStrings = Split(lStrOpenArg, "=")
Set lclsOpenArg = New clsOpenArg
lclsOpenArg.fInit arrSplitStrings(0), arrSplitStrings(1)
'
'See if we explicitly say ApplyProperties
'
mblnApplyProperties = (lclsOpenArg.pName = "ApplyProperties")
Debug.Print lclsOpenArg.pName & ":" & lclsOpenArg.pVal
Set cOpenArg = lclsOpenArg
End Function
Last edited: