M
Max Moor
Hi All,
I have a form that is opened by another form, to display some extended
data. I need to pass a user-defined structure and an SQL string to the
form being opened.
In a VBA module (not part of a form or report), I have my structure
defined as:
Public Type MyType
strOne As String
strTwo As String
<etc, etc>
End Type
In the "master" form, I have the code:
Dim typMyRecord As MyType
Dim strSQL As String
Dim avarOpenArgs(2) As Variant
Dim strOpenArgs As String
<some code that inits typMyRecord and strSQL>
avarOpenArgs(0) = typMyRecord
avarOpenArgs(1) = strSQL
strOpenArgs = Join(avarOpenArgs, "\")
DoCmd.OpenForm "frmSlaveForm", acNormal, , , , acDialog, strOpenArgs
Finally, in the"slave" form, I have:
Private gtypMyRecord As MyType
Private gstrSQL As String
Private Sub Form_Open(Cancel As Integer)
Dim avarOpenArgs As Variant
Dim strOpenArgs As String
If Not IsNull(Me.OpenArgs) Then
strOpenArgs = Me.OpenArgs
avarOpenArgs = Split(strOpenArgs, "\")
gtypMyRecord = avarOpenArgs(0)
gstrSQL = avarOpenArgs(1)
End If
End Sub
I've used this method to pass multiple string before, but when I
try it with my structure, I get a compile error saying:
"Only user-defined types defined in public object modules can be coerced
to or from a variant or passed to late-bound functions."
I thought I understood this error, but I thought I did have the
type defined in a public module. Of course, regardless of what I think,
I still get the error. Can anyone help me get my structure and string
passed to my form?
Thanks, Max
I have a form that is opened by another form, to display some extended
data. I need to pass a user-defined structure and an SQL string to the
form being opened.
In a VBA module (not part of a form or report), I have my structure
defined as:
Public Type MyType
strOne As String
strTwo As String
<etc, etc>
End Type
In the "master" form, I have the code:
Dim typMyRecord As MyType
Dim strSQL As String
Dim avarOpenArgs(2) As Variant
Dim strOpenArgs As String
<some code that inits typMyRecord and strSQL>
avarOpenArgs(0) = typMyRecord
avarOpenArgs(1) = strSQL
strOpenArgs = Join(avarOpenArgs, "\")
DoCmd.OpenForm "frmSlaveForm", acNormal, , , , acDialog, strOpenArgs
Finally, in the"slave" form, I have:
Private gtypMyRecord As MyType
Private gstrSQL As String
Private Sub Form_Open(Cancel As Integer)
Dim avarOpenArgs As Variant
Dim strOpenArgs As String
If Not IsNull(Me.OpenArgs) Then
strOpenArgs = Me.OpenArgs
avarOpenArgs = Split(strOpenArgs, "\")
gtypMyRecord = avarOpenArgs(0)
gstrSQL = avarOpenArgs(1)
End If
End Sub
I've used this method to pass multiple string before, but when I
try it with my structure, I get a compile error saying:
"Only user-defined types defined in public object modules can be coerced
to or from a variant or passed to late-bound functions."
I thought I understood this error, but I thought I did have the
type defined in a public module. Of course, regardless of what I think,
I still get the error. Can anyone help me get my structure and string
passed to my form?
Thanks, Max