toofaced
toofaced

Reputation: 151

Acess Compile error - user defined type not defined vba access

I am having this compile error in my Microsoft Access application. I recently started working on MS access. So I am new to code in VBA. I have an desktop application (Access 2003) in which list of companies need to be sorted once user click on the column header. It was working but once I click 'Compile', it is throwing me this error. If I comment out following code, my program does compile but sorting does not work. Please help.

Dim ListViews As New clsListViews
Private Sub lstVendorList_ColumnClick(ByVal ColumnHeader As Object)
   ListViews.SortColumns lstVendorList, ColumnHeader
End Sub

When I researched online. Many of people were talking about references. Under my references, I have checked

Microsoft DAO 3.6 Object Library
Visual Basic For Applications
Microsoft Access 9.0 object library.

Upvotes: 2

Views: 1221

Answers (1)

Mathieu Guindon
Mathieu Guindon

Reputation: 71187

Dim ListViews As New clsListViews

This instruction declares a module-level object variable named ListViews, of type clsListViews.

VBA looks everywhere it can for a class named clsListViews that it can create an instance of and assign that ListViews reference, and when it can't find it, it gives you the compile error you're seeing.

Make sure you only New up objects of types that exist. If it's not listed in IntelliSense/autocomplete when you type the space after New, it's probably not a legal type to use.

Upvotes: 2

Related Questions