Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109

    How to get handle to previously created custom object from a form?


    Hi Guys,

    I've created a custom class called "clsPerson". From a sub in standard module I'm creating new instance of my class, assign it all properties needed and triger its method "getForm". This method creates a form on the fly and place of necessary controls on it. It also assigns a vba code to one of its buttons. After all this is done, it saves the form and open it normally. When I click the button, it is supposed to call this already open clsPerson instance and triger one of its method. The problem is that I don't know how I can invoke to this already opened clsPerson instance. I can't create new clsPerson because the properties I need are stored within previously opened clsPerson. How can I work it around?

    Robert

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,526
    I dont see the need for a class when you can build a form and the form stores the fields.

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742

  4. #4
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    @ranman256 - this is all what I "love" about this forum: instead of answer for exactly asked question I always get "why do I want to do something like that?". If you don't see the reason, please keep it to yourself because I DO. In the nut shell, I'm trying to create a filter in the form of custom class. I want it to be as encapsulated as possible and it means it dynamically creating form, displaying it and killing once it's done. I want to be able to implement this filter to every access database by simple import of my class.

    @orange - The code of this object is 400-lines long. Should I paste it here or rather send you the file?

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    2 points:

    1. You can post a text or zip file or an accdb with code and examples.

    2. Regular forum people like ranman and I see lots of post/questions. My guess is that 80+% are related to
    posters who have just acquired Access, or those who have no experience with database concepts and are
    unaware of systems analysis or design. Many times the questions are focused on some obscure mechanism as to HOW to do techie term X using techie term Y, without any context of the underlying issue or description of the "business" involved.
    I see you have over 75 posts on this forum and have posed your question in context. Please don't be too harsh with ranman... I think he was just asking for a little more rationale re the use and need of a class.

    I am interested in learning and look forward to your file.

  6. #6
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Sorry, didn't want to be harsh or anything. For me posting a question on forum is a matter of last resort - it's always preceded by hours of googling the next. However, sometimes an issue is just so complex and abstract that there seem to be no short string to put into google that would bring good results. Especially that English is not my first language. I try to describe the issue as clearly as possible and expect same answer. If anyone feels offend by my previous post, I'm sorry, it wasn't my intention.

    I'll post a db later at home. There is just few things I have to remove first. Will keep you posted.

    Thank you for your support.

    Robert

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    Nobody is offended. You are an exception in that you exhaust googling and trying before posting. Many post first, and sometimes on multiple forums. Your English is very good--certainly better than most of us could do in a second language.

    As you will understand, communication is the key. Getting a well described issue in context, usually leads to a focused response/suggestion/options in the shortest post exchange.

  8. #8
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Attached is the database. When you press the "Press me" button, it will triger "xxx" sub on "advanceFilter" module. "xxx" then creates new instance of clsFilter class and add 3 objects of clsFilterItem (they represent different fields of the filter). Then new form "frmFilterContainer" is created with subform "frmFilterItem" and table "tbTEMPFilterValues" set as its sourceObject. The form is then opened. Once you hit either "+" or "-", I'd like the form to call that original istance of clsFilter and triger "SelectAll" or "DeselectAll" of clsFliterItem that is currently loaded. I don't know how should I get a handle of that existing instance of clsFilter or instances of existing clsFilterItem objects.
    I'm afraid I can't make it any clearer...
    Attached Files Attached Files

  9. #9
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    @orange Did you manage to test it?

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    I did get to execute your code, even stepped through it.
    I have created some classes but am certainly not expert in the area.
    I'm trying to figure our what exactly you are trying to do.
    Do you have a simple description of what you are doing?
    Purpose of each piece of code??
    I have asked someone more familiar with classes to have a look, but don't know his schedule at this time.
    There are not many comments within your code.

  11. #11
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Sorry for late response but I was away from computer whole weekend.
    I know there's very few comments - I still have to persuade myself into placing them. I know they are life-savior afterwards when you get back to code after some time for debugging, but still can't make myself.
    What I want to achieve, let's say, is to create filter as object-oriented as possible. I know vba is not truly OO language but I want to test where I can go with it. As for the beginning it seems bringing good results.
    As it turned out there was a misconception on my side - I wrongly assumed that my filter object or filterItems collection would be available and didn't take into account that my code has finished before I press the button. And then it refers to non-existing object. All perfectly logic but took a while to figure it out.. I'll place a temp table to keep my filter object for further operations and that should does it.

    Anyway, thank you for trying to help!

    Regards,
    Robert

  12. #12
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    I have to dig it up again as I'm still not done. Attached is newer version of same database but in more finished stage. If you click "Press me", "xxx" subroutine will do as follows:
    1. Create new instance of clsFilter object and use object methods to build objects for filter field and single value
    2. Create reusable table for filter values and filter fields
    3. Create 4 forms
    4. display main form


    The main form has as many buttons as fields I've added to my filter. By clicking "Wybierz" ("Choose") you should have "frmFilterContainer" form displayed that would allow you to choose which values of this filter field are to be included into final query.

    Now, what's weird is that it works, but only at the SECOND TIME! Let's put it this way, if you first click "Press me" my code checks whether the 4 needed forms exist and if they don't - it builds them. It also checks whether 2 needed tables are present and build them if not. So when you run it for the 1st time (when none of required forms or tables exist) it goes through all 4 points above but crash later when you put "Wybierz" button. Funny, but when you close main form and hit "Press me", the code will go through 1-4 but omitting points 2 & 3 (as forms & tables are present) and then when you hit "Wybierz", it will works as desired. Don't get it. Can someone check what I'm missing. It's driving me mad.

    Robert
    Attached Files Attached Files

  13. #13
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    No one? I've spent some more time testing my code, and it seems that the object of clsFilter is properly set on newly created subform but then somehow disappears. Analyze this short code:

    Code:
    Private newFil As clsFilter
    
    Private Sub btnChoose_Click()
    Debug.Print TypeName(newFil)
    Call newFil.updateItem(Text0.value) 'I got error "Object variable or With block variable not set". If test debug.print TypeName(newFil) it returns Nothing
    
    
    End Sub
    
    
    Private Sub Form_Open(Cancel As Integer)
    Set newFil = factory.filter
    DoEvents
    Debug.Print TypeName(newFil) 'this test returns "clsFilter" which proves that newFil (instance of clsFilter) exists here and is set correctly
    
    
    End Sub
    What's going on? Do I have to save the added module first or what? It doesn't seem so as Form_Open event triggers without issues.

    Robert

  14. #14
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    I've downloaded the db, but the code fails when trying to open tblProductSteps - it is a linked table

  15. #15
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Very sorry. I converted it to local table. Please test it now.
    Attached Files Attached Files

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Run a previously created Multiple times for a date range
    By unreal_event_horizon in forum Programming
    Replies: 3
    Last Post: 08-29-2014, 09:06 AM
  2. Replies: 3
    Last Post: 10-18-2012, 02:25 PM
  3. Replies: 2
    Last Post: 06-15-2012, 07:41 PM
  4. Replies: 3
    Last Post: 05-26-2011, 12:52 PM
  5. Replies: 10
    Last Post: 11-09-2010, 03:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums