MS Access VBA error message - help with coding

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.
 
V

Van T. Dinh

From Access Help:

OpenArgs Optional Variant. A string expression. This expression is used to
set the form's OpenArgs property.

I think this means that if the OpenArgs is supplied, it must be a String (or
something that Access VBA can type-cast into a String).

If you want to pass 2 or more values to the Form, simply concatenate them
using a separator like ";". When you want to use the values, use code to
separate them out (and convert to the required type if required).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top