Results 1 to 9 of 9

Thread: I'm having trouble creating Type's in VBA

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    68

    I'm having trouble creating Type's in VBA

    I made a type "Employee" in a class module.

    Option Compare Database

    Option Explicit


    Private Type Employee
    DateHired As Date
    FullName As String
    IsMarried As Boolean
    HourlySalary As Currency
    End Type

    Then I'm trying to assign a variable as this new user defined type
    in a sub function.

    Private Sub cmdCreate_Click()
    Dim Contracter As Employee

    Contracter.DateHired = #12/4/2004#
    Contracter.FullName = "James McNeil"
    Contracter.IsMarried = False
    Contracter.HourlySalary = 10

    txtDateHired = Contracter.DateHired
    txtFullName = Contracter.FullName
    chkIsMarried.Value = Contracter.IsMarried
    txtHourlySalary = Contracter.HourlySalary


    End Sub

    but an error saying " method or data member not found" keeps popping up for the .datehired

    any suggestions?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: I'm having trouble creating Type's in VBA

    VBA question moved to Office Development.

    BTW: I had no problem running your code using VB6 so it has to be something with VBA. These folks should know.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: I'm having trouble creating Type's in VBA

    I'm not sure about VBA (and this should be moved to the proper forum), but in VB it would be
    VB Code:
    1. Contracter.DateHired = "12/4/2004"
    Try that.

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: I'm having trouble creating Type's in VBA

    are u trying to access the Type outside of the class module??

    it seems that way since its under cmdCreate....

    put it in a reg bas module.. and declare it as Public
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: I'm having trouble creating Type's in VBA

    Quote Originally Posted by Al42
    I'm not sure about VBA (and this should be moved to the proper forum), but in VB it would be
    VB Code:
    1. Contracter.DateHired = "12/4/2004"
    Try that.
    no its a DATE do #12/4/2004# would be correct
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    68

    Re: I'm having trouble creating Type's in VBA

    Quote Originally Posted by Hack
    VBA question moved to Office Development.

    BTW: I had no problem running your code using VB6 so it has to be something with VBA. These folks should know.
    yea i figured that was the main issue. thing is i been trouble shooting using vba sites and they are telling me what i did was ok. so iono

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    68

    Re: I'm having trouble creating Type's in VBA

    Quote Originally Posted by Static
    are u trying to access the Type outside of the class module??

    it seems that way since its under cmdCreate....

    put it in a reg bas module.. and declare it as Public
    that's what i tried at first. and it said i the type wasn't recognized!
    so i made a class module and ran it, and it recognized the type but said the the .datehired couldn't be found

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    68

    Re: I'm having trouble creating Type's in VBA

    uhhhhhh,thanks static. it worked, lmao.
    i guess i had it as private in the regular module
    sorry dudes

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: I'm having trouble creating Type's in VBA

    glad it was an easy one... wasnt makin sense till I saw that.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width