Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Location
    Gatineau, Quebec Canada
    Posts
    147
    Provided Answers: 1

    Unanswered: UDTs and MS Access 2003

    Greetings all,

    I am by the way back in Canada from southern China now. Great weather here ....-20! Such is life.

    I have been trying to work with user defined types (UDTs) in MS Access2003, mostly because I want to return two things (a time and a date) through a function. I get the 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."

    My UDT looks like this:

    Public Type mySchedule
    aDate As Date
    aTime As Date ' don't think there is an actual time type in Access
    End Type

    I have tried using 'Variant' instead of "Date" or "String". No effect.

    Does Access 2003 support UDTs or not? If it does, can anyone suggest a tutorial,reference or even examples for the use of UDTs?

    Anyone have any idea what the error message means?

    Regards

    John S

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    It means that you must declare your mySchedule type in the declaration section of an independant module, not in the declaration section of a form module and not in the declaration section of a class module.
    Have a nice day!

  3. #3
    Join Date
    Mar 2009
    Location
    Gatineau, Quebec Canada
    Posts
    147
    Provided Answers: 1

    UDTs and 2003

    Hi,

    Thanks for the reply. It is surprising how little information is on the net about using UDTs in MS Access. I was able to get some code using a UDT that worked, so as far as I can see, Access 2003 does support UDTs.

    The code (obtained elsewhere, and modified slightly)below functions in the main (at least only)module. The types can be public or private.

    Public Type dict
    a As Integer
    b As String
    c As String
    d As Integer
    End Type

    Private Function defineDict() As dict
    defineDict.a = 1
    defineDict.b = "two"
    defineDict.c = "three"
    defineDict.d = 4
    End Function

    Sub testType()
    Dim t As dict ' Set the variable
    t = defineDict ' Initialize
    Debug.Print t.b
    MsgBox t.b
    ' Prints >> "two"
    t.b = "no more" ' Change a variable
    Debug.Print t.b ' Prints >> "no more"
    MsgBox t.b
    MsgBox t.c
    End Sub

    I will do some further testing, and let everyone know what I find.

    Thanks again

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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