Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 15th, 2011, 05:26 PM
Authorized User
Points: 66, Level: 1
Points: 66, Level: 1 Points: 66, Level: 1 Points: 66, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
Default Trouble Compiling VBA after Using Interfaces

All right, I was reading through the Access 2010 Programmers Reference, which I have been enjoying, by the way, and started playing around with interfaces and "Object Oriented Programming". OOP being a prior interest of my own, this seemed natural.

Anyways, after all sorts of trouble I was able to produce a working version of a group of interfaces and classes that mimic enumeration values on other languages. It works when I use them in an access application, but when I try to compile the database, I get this error: "User-defined Type Not Defined"
I wasn't going to post the code for length issues, but here is the code for the interface and implimentation (there is an enum and two helper functions used as well) and try to make it as short as possible.

Here is the interface IEnumPlus
Code:
Option Compare Database
Option Explicit

'Size of the Enum
Public Property Get Size() As Long
End Property

'Array with all the accessible enum values. Should be dynamically created on object initialization
Public Property Get Values() As Collection
End Property

'The name of the enum value
Public Function Name(eVal As Long) As String
End Function

'The name of all the values in the enumueration, also created on initialization
Public Property Get Names() As Collection
End Property

'Label of enum value as needed to be seen by the user
Public Function Label(eVal As Long) As String
End Function

'Initialized array of all user labels
Public Property Get Labels() As Collection
End Property

Public Property Let UT(eVal As utUserType)
End Property

Public Property Get UT() As utUserType
End Property

Public Property Get UTLong() As Long
End Property

Public Property Let UTString(sVal As String)
End Property
And here is the implementation:

Code:
Option Compare Database
Option Explicit

Implements IEnumPlus

Private eValues As New Collection
Private nValues As New Collection
Private labValues As New Collection

Private inUT As utUserType


Private Sub Class_Initialize()
    Dim aCount As Integer
    For aCount = 0 To 10
        eValues.Add (2 ^ aCount)
        nValues.Add IEnumPlus_Name(eValues.Item(aCount + 1))
        labValues.Add IEnumPlus_Label(eValues.Item(aCount + 1))
    Next aCount
End Sub

Public Property Get IEnumPlus_Size() As Long
    IEnumPlus_Size = 11
End Property

Public Property Get IEnumPlus_Values() As Collection
    Set IEnumPlus_Values = eValues
End Property

Public Function IEnumPlus_Name(eVal As Long) As String
    IEnumPlus_Name = UserType.UTName(eVal)
End Function

Public Property Get IEnumPlus_Names() As Collection
    Set IEnumPlus_Names = nValues
End Property
Public Function IEnumPlus_Label(eVal As Long) As String
    IEnumPlus_Label = UTLabel(eVal)
End Function

Public Property Get IEnumPlus_Labels() As Collection
    Set IEnumPlus_Labels = labValues
End Property

Public Property Let IEnumPlus_UT(eVal As utUserType)
    inUT = eVal
End Property

Public Property Get IEnumPlus_UT() As utUserType
    UT = inUT
End Property

Public Property Get IEnumPlus_UTLong() As Long
    UTLong = CLng(inUT)
End Property

Public Property Let IEnumPlus_UTString(sVal As String)
    Select Case sVal
        Case UT1NAME, UT1LABEL
            inUT = utREAD_LIMITED
        Case UT2NAME, UT2LABEL
            inUT = utREAD_LIMITED2
        Case UT4NAME, UT4LABEL
            inUT = utREAD_ONLY
        Case UT8NAME, UT8LABEL
            inUT = utSTANDARD
        Case UT16NAME, UT16LABEL
            inUT = utSTANDARD2
        Case UT32NAME, UT32LABEL
            inUT = utSTANDARD3
        Case UT64NAME, UT64LABEL
            inUT = utPOWER_USER
        Case UT128NAME, UT128LABEL
            inUT = utPOWER_USER2
        Case UT256NAME, UT256LABEL
            inUT = utMANAGEMENT
        Case UT512NAME, UT512LABEL
            inUT = utMANAGEMENT2
        Case UT1024NAME, UT1024LABEL
            inUT = utDEVELOPER
    End Select
End Property
Is there something I have done wrong, or something I could do to get this to compile properly?
Reply With Quote
  #2 (permalink)  
Old March 31st, 2011, 08:50 AM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Make Sure Your Code is in Access Code Modules

Hello drexasaurus,

I saw your post about "Trouble Compiling VBA after Using Interfaces" when using the Implements VBA Keyword in your Access VBA Modules...and I think I know what the problem might be. Be sure to put both of these sets of code in an Access VBA "Class Module" (and not a regular module). Otherwise, you will get the error message:

"Only valid in object module"

When trying to compile your Access Database Application. Anyway, that is my guess, but if that is not the case and you are still having problems, please let me know!

Also, thanks for the GREAT feedback on the Access 2010 Programmer's Reference, I'm glad you have found it useful! We always love to hear the feedback !

Good luck,

Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two interfaces with Same function name Manoj Bisht C# 2005 5 March 25th, 2009 09:52 AM
interfaces malli_kv2 Java Basics 1 April 23rd, 2007 05:21 AM
Trouble hiding and unhiding columns in VBA jtmelb Excel VBA 0 February 14th, 2007 07:04 PM
Excel vba trouble liam.emmett Excel VBA 4 January 30th, 2007 10:58 AM
Compiling trouble Polymer Javascript How-To 1 March 25th, 2005 03:35 AM



All times are GMT -4. The time now is 12:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.