PDA

Click to See Complete Forum and Search --> : I'm having trouble creating Type's in VBA


southphillyman
Apr 27th, 2006, 09:41 AM
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?

Hack
Apr 27th, 2006, 09:59 AM
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. :)

Al42
Apr 27th, 2006, 10:00 AM
I'm not sure about VBA (and this should be moved to the proper forum), but in VB it would be Contracter.DateHired = "12/4/2004" Try that.

Static
Apr 27th, 2006, 10:03 AM
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

Static
Apr 27th, 2006, 10:04 AM
I'm not sure about VBA (and this should be moved to the proper forum), but in VB it would be Contracter.DateHired = "12/4/2004" Try that.

no its a DATE do #12/4/2004# would be correct

southphillyman
Apr 27th, 2006, 10:13 AM
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

southphillyman
Apr 27th, 2006, 10:14 AM
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

southphillyman
Apr 27th, 2006, 10:18 AM
uhhhhhh,thanks static. it worked, lmao.
i guess i had it as private in the regular module
sorry dudes

Static
Apr 27th, 2006, 10:34 AM
;) glad it was an easy one... wasnt makin sense till I saw that.