[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Passing an object to a form

Posted on 2008-11-13
15
Medium Priority
?
229 Views
Last Modified: 2012-05-05
I created a generic "Open Form" prodedure that will do some standard formatting to a form before it opens.  Worked great when forms were bound.  However, I'm switching over to an OOD and need to pass objects into a form. The best way I've come up with is have a public subroutine within the form's module.  

When I've explicitly called the subroutine (i.e. Set frmForm = FORM_frmWhatever), I can call the subroutine.  However, when I try to call the subroutine from a generic Form object, I get a "Application-Defined Error."  Any help would be appreciated.
Sub OpenForm(strFormName as string, Optional objObject as Object)        
dim frmFrom as form
set frmform = forms(strformname)
If Not objObject Is Nothing Then   
   frmForm.CustomSub 'Application Error Here
End If
 frmform.visible = true
end sub

Open in new window

0
Comment
Question by:droy0521
  • 8
  • 4
  • 3
15 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 22956844
In lines 2 and 3, you use different spellings for your objects: frmFrom vs frmform
dim frmFrom as form
set frmform = forms(strformname)

0
 

Author Comment

by:droy0521
ID: 22956887
That was just a typo when I rewrote the code to get rid of some of the other procedures that are called prior to the sending of the object to the form.  Below is the direct copy and past from my modules.
'****************************************************************************************
Public Function OpenForm(strFormName As String, _
    Optional strWHERE As String, _
    Optional objObject As Object)
On Error Resume Next
    Dim frmForm As Form
 
    gstrCallingForm = Screen.ActiveForm.Name
 
On Error GoTo HandleError
    Set frmForm = GetForm(strFormName)
    
    With frmForm
        
        FormatFormDefaults frmForm
        
        If Not objObject Is Nothing Then
            
            frmForm.GetObject objObject
            
        End If
        
        If strWHERE <> "" Or Not IsNull(strWHERE) Then
            
            .FilterOn = True
            .FilterOnLoad = True
            .Filter = strWHERE
        End If
        
        .visible = True
        ChangeFormView .Name, acNormal
 
    End With
    
Exit_Function:
Exit Function
HandleError:
    Select Case Err.Number
        Case 2450 'Form Already closed, happens when user opens a form from within itself
            Resume Next
        Case Else
            GeneralErrorHandler Err.Number, Err.Description, MODULE_NAME, "OpenForm"
    End Select
    GoTo Exit_Function
End Function
 
FROM THE FORM:
Public Sub GetObject(objSentMember As Object)
    
    Set objMember = objSentMember
    
End Sub

Open in new window

0
 
LVL 75
ID: 22956892
Try this:

frmForm_CustomSub()

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Author Comment

by:droy0521
ID: 22956907
No that didn't work either.  It thinks you're trying call a procedure.
0
 
LVL 75
ID: 22956919
"It thinks you're trying call a procedure."

Isn't that what you are trying to do?  If not, what ?

mx
0
 

Author Comment

by:droy0521
ID: 22956940
Sorry, I should have been more specific.  The compiler thinks I'm trying to call a procedure name "frmForm_GetObject" when really I'm trying to call the procedure "GetObject" which is within the frmForm module.
0
 

Author Comment

by:droy0521
ID: 22956959
Let me be a little bit more specific.  I have the intention of creating a procedure called "GetObject" in every form that I make unbound.  What I want the procedure OpenForm to do is: if an object is passed into it, then to pass the object onto the form which is being opened.  The form will then set its controls' values according to the properties of the object.

thanks,
Dennis
0
 
LVL 75
ID: 22956961
So, you are trying to pass the name of a procedure in Optional objObject as Object ... the call that procedure in the code?

mx
0
 

Author Comment

by:droy0521
ID: 22957315
There's two different examples below.  The first one works, but the second one does not.  I need to make the second one work.


Example #1 - Works
Sub OpenForm(Optional objObject as object)
    Set frmForm = New Form_pfmMemberClubEnrollment
    If Not objObject Is Nothing Then
       frmForm.GetObject objObject
    End If
Exit Sub
 
Example #2 - Doesn't work
Sub OpenForm(strFormName as string, Optional objObject as Object)
 Dim frmForm as Form
  Set frmForm = Forms(strformname)
        If Not objObject Is Nothing Then
            frmForm.GetObject objObject
        End If
exit sub

Open in new window

0
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 1500 total points
ID: 22957404
It seems to me that you are passing the form name as a string without its methods.  Try it this way

Example #2
Sub OpenForm(frmForm as Form)
   Set frmForm = Forms(frmForm.Name)
 exit sub
0
 

Author Comment

by:droy0521
ID: 22961628
Unfortunately, that didn't work either.  Apparently, I need to look for another technique for passing the objects into the form.  
0
 
LVL 75
ID: 22961652
I'm not really clear on what this 'object' is ... and what you are going to do with it ?

mx
0
 

Author Comment

by:droy0521
ID: 22961930
I'm designing a database for tracking all of the 4-H members that I coordinate for the county I work at.  Each member record has about three or four other tables it has one-to-many relationships with (clubs, projects, exhibits, etc.).  With all of the relationships & volume of records/indexes, performance was starting to suffer & I wanted to have an eye on going multi-user in the future.  So I decided to convert the database over to an Object Oriented Design.  So I've made some custom classes (members, leaders, parents, etc).  Most of these of these classes has custom collections as properties of themselves.

So for instance, I have a member who is enrolling in a new club.  My standard form has a button that opens a popup form (which then has two list boxes, one with possible to clubs the member could join, the other with clubs the member is already enrolled in).  Since the "base form" is object oriented, the goal was to pass the member object/class from the base form to the popup form(s).  My goal was to minimize the number of connections to the backend dataset, since all of the information had already been loading into the object.

Does that make sense?  
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 22965367
I just got back on-line.  It didn''t work because I did not give you the entire picture.  This should work.

Code in the calling form:
Call OpenForm(Me)
___________________________
Code in the called sub :
Sub OpenForm(frmForm as Form)
   Set frmForm = Forms(frmForm.Name)
 exit sub
0
 

Author Closing Comment

by:droy0521
ID: 31516647
I finally figured it out.  The comment about not having the methods to the form led me to doing some troubleshooting.  in my "OpenForm" procedure, I had changed the form to design view while it was hidden.  Because ti was in design view, I couldn't reference the methods of the form.  It works now that I moved some of the sequencing around.

thanks,
Dennis
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question