Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912

    Unanswered: Public UDT Form Property - can't pass value

    Hi

    Moderately tricky - I think I know a solution but wouldn't mind some other minds on the case in case I have missed something.

    I have created a public property let statement for a form. This property is for a User Defined Type. I have a procedure that opens the form and then attempts to set the UDT. However, the code errors and I get:

    "Only user-defined types defined in public object modules can be
    coerced to or from a variant or passed to late bound functions."

    I have googled but not really come up with much other than it looks like I might want to wrap up my UDT in a class. Or just create a class and drop the UDT. Anyway - here is the code. Any suggestions welcome.

    Code:
    'The UDT
    Public Type MyType
    	MyFirstVal As String
    	MySecondVal As String
    End Type
     
    'The declarations and properties of the form.
    'There is a String property just to check the problem is UDTs not property syntax
    Private mudtMyType As MyType
    Private mstrValue As String
     
    Public Property Let ChangeMyType(udtMyType As MyType)
     
    	mudtMyType = udtMyType
     
    End Property
     
    Public Property Let CheckPropertySyntax(StringInput As String)
     
    	mstrValue = StringInput
     
    End Property
     
     
    'Command button on another form to open the UDT form and set the property
    'If the line <frm.ChangeMyType = udtMT> is commented out, code works fine and string property is set.
    'Uncomment and the code fails with the above error message.
    'I've used <Dim frm As Form_UDTForm> to see if I could get round this late binding thing. DoCmd.OpenForm elicits the same error
    Dim frm As Form_UDTForm
     
    Private Sub cmdUDT_Click()
    On Error GoTo Err_cmdUDT_Click
     
    	Dim udtMT As MyType
    	Const FName As String = "UDTForm"
     
    	udtMT.MyFirstVal = "Foo"
    	udtMT.MySecondVal = "Bar"
     
    	Set frm = New Form_UDTForm
     
    	frm.Visible = True
     
    	frm.CheckPropertySyntax = "FooBar"
     
    '	frm.ChangeMyType = udtMT
     
    Exit_cmdUDT_Click:
    	Exit Sub
     
    Err_cmdUDT_Click:
    	MsgBox Err.Description
    	Resume Exit_cmdUDT_Click
     
    End Sub
    Testimonial:
    pootle flump
    ur codings are working excelent.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You've basically already answered your question. You're more or less talking about extending the form class. The simplest solution would be to wrap your type in a class module, and then create objects as needed. You could create a "parent_form" property for your class to assign it to a target form, or perhaps create a public or otherwise persistant instance of your class inside your form declarations.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Cheers Teddy

    I was mostly being lazy plus this is the first time I have really found a genuine use for UDTs so I was hoping to be able to use one. Never mind - I'll pop toether a class if there is no alternative. Thanks for the help

    Ta
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    no reason you can't use it... you just have to declare it somewhere else

    What stops you from declaring your object as private static, then exposing it through public subs?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by Teddy
    no reason you can't use it... you just have to declare it somewhere else

    What stops you from declaring your object as private static, then exposing it through public subs?
    What's my object? You mean the one I have yet to build to house\ replace my UDT? If so, I guess no reason. EDIT - Oh - you mean the UDT. Hmm - yes, that makes better sense than what I currently have.

    Although I am starting to back track and think that I might put the data I intended to pass to the form via an UDT into a table. I've had a lot of success putting application information into tables recently (the idea is to make the application as presentation-layer-independant as possible with a view to a future migration to .NET) so I might follow this route instead. Something to ponder.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •