Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-09-2016, 06:32 PM   #1
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,214
Thanks: 89
Thanked 2,021 Times in 1,969 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Seeking articles/examples set up Library file in 2010

I have created library files (mda) in 2003. I have tried to use that library with Access 2010. It is referenced and shows up in the Project window.
When I try to reference a class module from the library file using the new keyword, I get an error (commented out in red below). However, if I use a class module clsTimer, that is resident in my main database, the New keyword is acceptable.

cStringX can be seen in the library, and methods/properties seen via Object browser. Intellisense show these as well.

Can someone point me to reference materials and examples related to library files using 2010, and/or the issue with the new keyword??

Code:
'---------------------------------------------------------------------------------------
' Procedure : demoClass_CstringX
' Author    : mellon
' Date      : 08/04/2016
' Purpose   :Trying this old class module cStringX.
' Issues with the mda library; having syntax issues trying to use NEW
'---------------------------------------------------------------------------------------
'
Sub demoClass_CstringX()
 Dim omystring As cStringX
 'Set omystring = New cStringX
   On Error GoTo demoClass_CstringX_Error

 Set omyString = cStringX
 Dim otime As clsTimer
 Set otime = New clsTimer
 omyString.Value = "This is a test string to show the functionality of this class"
 Debug.Print "String value : " & omyString.Value
 Debug.Print "String reversed : " & omyString.Reverse
 Debug.Print "String Length : " & omyString.Length
 Debug.Print "String Starting " & omyString.startingchar
 Debug.Print "String Starting 6 chars :" & omyString.startingchar(6)
 Debug.Print "String Ending 5 chars :" & omyString.endingchar(6)
 Debug.Print "String contains (zz) " & omyString.contains("zz")
 Debug.Print "String contains nc " & omyString.contains("nc")
 Debug.Print "String has char at position 7: " & omyString.charat(7)
 Debug.Print "String upper " & omyString.toProper
 Debug.Print "Time taken(ticks): " & otime.EndTimer
   On Error GoTo 0
   Exit Sub

demoClass_CstringX_Error:

    MsgBox "Error " & Err.Number & " in line " & Erl & " (" & Err.Description & ") in procedure demoClass_CstringX of Module Module4"
End Sub

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by jdraw; 04-09-2016 at 06:40 PM.
jdraw is offline   Reply With Quote
Old 04-09-2016, 07:02 PM   #2
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
AFAIK you need to write a public function in the library database that returns the new instance. So if you have a clsCustomClass in a library database, you should include, in a standard module in that library, a public function like . . .
Code:
Public Function NewCustomClass() as clsCustomClass
   Set NewCustomClass = New clsCustomClass
End Function
. . . which returns a new instance of the class.

I believe that in VBA you can only directly create (using the 'New' keyword) VBA classes that are defined in the current project.
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Old 04-09-2016, 07:18 PM   #3
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,214
Thanks: 89
Thanked 2,021 Times in 1,969 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Seeking articles/examples set up Library file in 2010

Thanks Markk.

My testing was leading me to your point
I believe that in VBA you can only directly create (using the 'New' keyword) VBA classes that are defined in the current project.

Do you have any links/articles regarding creation of Library (code file) fro A2010? My googling effort is drawing a real blank.

I was trying to adjust a class module based on this
http://access.mvps.org/access/modules/mdl0034.htm

I exported the class, modified the Exposed and Creatable values to True (as I had read) using Notepad++, then inserted the revised text(class module code) into a new class. All seemed fine, but the VERSION and Begin End

Code:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "cStringEX"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True.....
........
Showed up in red --invalid outside a procedure...

I have a feeling things have changed between 2003 and 2010, but I can't (haven't yet) find a good reference for details/sample.

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by jdraw; 04-09-2016 at 07:54 PM.
jdraw is offline   Reply With Quote
Old 04-10-2016, 12:50 PM   #4
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
I think you can set those properties in the IDE using the Properties windows.

1) Click main menu View->Properties Window (or hit <F4>)
- opens the Properties Window
2) Select the class you want to expose in the Project Explorer.
- Note the "Instancing" property of the selected class in the Properties Window!
3) Change the Instancing property from "1 - Private" to "2 - PublicNotCreatable"
- Once set, the class will be visible as a valid type in databases that reference this library file.
- But you still need a public function in the Library file to return a new instance of the class.
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
The Following User Says Thank You to MarkK For This Useful Post:
jdraw (04-10-2016)
Old 04-10-2016, 01:23 PM   #5
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,214
Thanks: 89
Thanked 2,021 Times in 1,969 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Seeking articles/examples set up Library file in 2010

Thanks again Markk.
Yes, I just tried the Properties window and saw the option. I just dug out some old code from when I was working (retired 8+yrs).

It's funny, I do remember having to create a function to do something like you advised.
I don't recall details, but having done as you said, I'm saying to myself --jeez I think someone had told me that years ago.

Thanks again works great!

Still looking for good reference material re classes etc.

Seems to be hidden away????
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
Old 04-10-2016, 02:10 PM   #6
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
Check out this site . . .
http://www.cpearson.com/excel/classes.aspx
It says Excel, but it's VBA, and everything applies to Access. It's a sort of "Class Modules 101" for VBA.

And yes, agreed, there is not much reference material for OOP principles in VBA. Mostly I theorize that if people want to do OOP solutions they migrate to languages that support OOP better than VBA, but to my mind, it's still worthwhile, if you can get your head around it, to use classes in VBA. I encapsulate all business logic for a type, say cCustomer, in a class module in any system I write. It becomes THE single location where business logic for that type resides. Then I can instantiate that type on the Customer Form, or the Customer Subform, or the Customer report, etc... That way my UI is never bound directly to any business logic. All the business logic is in the class, etc...

Also, if you have other questions in this vein, I'd be happy to take a crack at answering, or at least participate in any discussion of the use of classes if that would help.

All the best,
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Old 04-11-2016, 10:26 AM   #7
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,214
Thanks: 89
Thanked 2,021 Times in 1,969 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Seeking articles/examples set up Library file in 2010

Thanks once again Markk.

I did put a list of links in this thread
http://www.access-programmers.co.uk/...d.php?t=270135
and when I went back to it, I see you have added a lot of info.

I'm going to look at the samples you added and some of the other links.

I don't have specific questions at the moment, but, being retired and not working in any development, it's more of an interest thing.

After a little review, I can see that you and Chris (stopher) have a real handle on this stuff. Much superior to the rest of us "dabblers".

It would be good to see a list of youtube or other videos on classes and their use.

jdraw


__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by jdraw; 04-11-2016 at 12:46 PM.
jdraw is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2010/Windows 7 Library Issue deltagracesun Modules & VBA 1 02-06-2014 12:00 PM
MS Office 2010 update caused Missing Reference MSO.DLL and MSOffice15 Object Library Rx_ Access Web 2 10-23-2013 07:54 AM
Problems setting up a Database Library File. highandwild Modules & VBA 1 07-28-2013 01:32 PM
Import text file examples sumdumgai Modules & VBA 4 03-18-2010 11:43 AM
.mde file Cant find project or library nuttychick General 1 06-16-2005 12:29 AM




All times are GMT -8. The time now is 01:01 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World