Hi Matt, I am not doing much programming these days, and I don't have a super expert answer for you.
.But I imagine there might be some use in a class for each field -- if anything though, I would think the first and most useful step might be to create a class for your database (something akin to an ADO recordset used for referring to an SQL database or a subset of it's records) and a class for a database record. The database class could offer the capability to filter the records, and provide a collection of records. The record class could provide properties for the different fields, or if designed in a more generic way instead, a collection of fields. the Record object could store changes in it's fields without effecting the table/database until a method of the record is executed along the lines of .SaveRecord. All of this serves to create a layer of abstraction that might be useful in simplifying the rest of your form code. It also enables you to easily and consistently work with that data from any code in your workbook without re-inventing the wheel each time, or worrying about changing code in many places in standard modules, because with this abstraction of your database, if something about the underlying database structure changes, or the workbook structure, you only need to update the classes. It would be best to find an example that does something like that (or whatever the real "super experts" recommend) and look at the code. By the way, a UserForm is really a class, and it's code is really a class module. When you refer to a UserForm, Excel automatically creates a default instance of it and maintains a reference to that instance in the UserForms collection. You can create as many instances of the same form as you want, which since they are separate objects, will each have independent private variables and state. This could allow a user to work on two records at once, for example, in separate instances of the same form. In a simple implementation of that, you could create module-level variables to maintain references to each form: Public UserForm1_1 As UserForm1, UserForm1_2 As UserForm1 And whenever you want to show those forms, in your code, you could do this: If UserForm1_1 Is Nothing Then Set UserForm1_1 = New UserForm1 If UserForm1_2 Is Nothing Then Set UserForm1_2 = New UserForm1 UserForm1_1.Show UserForm1_2.Show You would probably want the form's ShowModal property to be set to False so that the user can interact with other windows at the same time. Asa From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] On Behalf Of Matt Sent: Thursday, April 12, 2012 6:09 AM To: excel-macros@googlegroups.com Subject: Re: $$Excel-Macros$$ Call a Function That helps alot Asa, now I understand why I see that people use classes when working with Userforms. I can also use them when working with objects such as charts. As far as what I read online, the subs should dictate the flow of the program and the classes should manage the individual objects such as charts, userforms. Sorry to be a pest...final question... If I wanted to create a mini program that shows data from an excel database would classes be useful?. For example, If I had a userform, and wanted to scroll and select someones name...and then in other boxes within the userform it will show their street, zip code, and country... can each one of those fields use a class? I'm trying to gain applicable examples to help gain an understanding. I have been using a few books for reference... but your explanations have helped me jump the learning curve... Matt On Wednesday, April 11, 2012 5:00:08 PM UTC-4, Asa R. wrote: The reason you can't call a method (sub or function member of a class) directly is because the object defined by the class doesn't exist until you create it with the NEW keyword (or CreateObject - but usually you should use NEW). It doesn't exist for a reason - each time you use the NEW keyword you create a unique entity - that object is an individual., and the variables, methods, properties, etc. of that object have their own scope. a CLASS is a "class of object". If you imagine a class called PERSON, it might have a property called "First Name" and another called "Last Name". If you could access those properties without "instantiating a class" (creating an instance of the class, i.e. a new object based on it) every PERSON in the world would have to have the same name (and everything else about them would have to be the same, and they would have to behave the same.). WORKSHEET is an example of a built-in class. You can't refer to it's properties and methods unless you refer to a specific worksheet object. Excel automatically creates WORKSHEET objects worksheets are added to the workbook, and disposes of them when they're removed. You can find some tutorials for classes online, such as: http://www.cimaware.com/resources/article_39.html http://www.cpearson.com/excel/classes.aspx Asa From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] On Behalf Of Matt Sent: Wednesday, April 11, 2012 6:21 AM To: excel-macros@googlegroups.com Subject: Re: $$Excel-Macros$$ Call a Function Yes, I moved it to another module and I believe I had an older copy of that code in a different module as well and that was a problem too. I've been trying to understand classes (I know they create objects) and their use, thats why I originally used the "class module" though. On Tuesday, April 10, 2012 9:53:09 PM UTC-4, Asa R. wrote: Hi Matt, Glad to help. What was your solution? Moving the functions to a standard module instead of the class module? Asa From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] On Behalf Of Matt Sent: Tuesday, April 10, 2012 6:03 PM To: excel-macros@googlegroups.com Subject: Re: $$Excel-Macros$$ Call a Function Thanks Asa. Your advice helped! I thought I tried it before but I guess I missed something and it works now. Tx again' Matt On Thursday, April 5, 2012 3:27:51 PM UTC-4, tag wrote: please see... Sub or Function not defined (Visual Basic) A Sub or Function must be defined in order to be called. Possible causes of this error include: . Misspelling the procedure name. . Trying to call a procedure from another project without explicitly adding a reference to that project in the References dialog box. . Specifying a procedure that is not visible to the calling procedure. . Declaring a Windows dynamic-link library (DLL) routine or Macintosh code-resource routine that is not in the specified library or code resource. To correct this error 1. Make sure that the procedure name is spelled correctly. 2. Find the name of the project containing the procedure you want to call in the References dialog box. If it does not appear, click the Browse button to search for it. Select the check box to the left of the project name, and then click OK. 3. Check the name of the routine. 2012/4/5 ChilExcel <chilexcel...@gmail.com> Please attach example, to better understand Chilexcel 2012/4/5 Matt <moni...@gmail.com> Hello, I'm trying to call a public function in one module from another Sub procedure in another module and it won't call the the function. I get an error that says.."sub function not defined" But when I include the function within the same module, my code works... I can't seem to find the answer online... What is the problem? Thanks again for your help. Matt -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ---------------------------------------------------------------------------- -------------------------- To post to this group, send email to excel-macros@googlegroups.com -- Visita ; http://sites.google.com/site/chilexcel/Home Visita ; http://www.youtube.com/user/timextag41 -- Visita ; http://sites.google.com/site/chilexcel/Home Visita ; http://www.youtube.com/user/timextag41 -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ---------------------------------------------------------------------------- -------------------------- To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ---------------------------------------------------------------------------- -------------------------- To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ---------------------------------------------------------------------------- -------------------------- To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com