I'm having trouble creating Type's in VBA
I made a type "Employee" in a class module.
Quote:
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.
Quote:
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?
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. :)
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:
Contracter.DateHired = "12/4/2004"
Try that.
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
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:
Contracter.DateHired = "12/4/2004"
Try that.
no its a DATE do #12/4/2004# would be correct
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
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
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
Re: I'm having trouble creating Type's in VBA
;) glad it was an easy one... wasnt makin sense till I saw that.