M
Mark
Help please
Can a guru please help me with my code. I am not sure whether
it is just my machine complaining, a bug in Access, it can't be done, or my
code is crap. I am getting a VBA error message (below) but here are all the
steps to reproduce the problem.
1. Launch MS Access 2000 and create new blank database called "Db1"
2. Create a new module called "Module1". Paste the following code
Public Type myType
str As String
int As Integer
End Type
Public xxx As myType
3. Create a new form called "Form1". Put a label on it.
4. Create a new form called "Form2". Put a button called "Command1" on it.
5. Build a click event for "Command1" and paste the following code into the
VBA editor.
Private Sub Command1_Click()
MsgBox "Button Clicked"
xxx.int = 1
xxx.str = "test"
DoCmd.OpenForm "Form1", OpenArgs:=xxx
End Sub
6. Close VBA, open "Form2", and press F5 to run. Click on the button you
added in step 4. A message box comes up and says "Button Clicked" so I know
it is working up to this point. But then I get this error message.
"Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late-bound functions"
I want to pass a user defined type to Form1, not a string, and can't seem to
get the syntax right. What's wrong.
Thank you all for your help.
Mark T.

it is just my machine complaining, a bug in Access, it can't be done, or my
code is crap. I am getting a VBA error message (below) but here are all the
steps to reproduce the problem.
1. Launch MS Access 2000 and create new blank database called "Db1"
2. Create a new module called "Module1". Paste the following code
Public Type myType
str As String
int As Integer
End Type
Public xxx As myType
3. Create a new form called "Form1". Put a label on it.
4. Create a new form called "Form2". Put a button called "Command1" on it.
5. Build a click event for "Command1" and paste the following code into the
VBA editor.
Private Sub Command1_Click()
MsgBox "Button Clicked"
xxx.int = 1
xxx.str = "test"
DoCmd.OpenForm "Form1", OpenArgs:=xxx
End Sub
6. Close VBA, open "Form2", and press F5 to run. Click on the button you
added in step 4. A message box comes up and says "Button Clicked" so I know
it is working up to this point. But then I get this error message.
"Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late-bound functions"
I want to pass a user defined type to Form1, not a string, and can't seem to
get the syntax right. What's wrong.
Thank you all for your help.
Mark T.