Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    103

    Unanswered: Returning Data from a form

    I want to be able to call form 2 (say frmContactMaster) from form 1 (say frmServiceWorkOrder), allow the user to add/edit data, and then return the value to the calling field.
    Imagine I am entering a service work order, and I want to use a contact that is not in the list, not in list property tells the user to doubleclick to add a contact.
    The user doubleclicks, which triggers stDocName, , , stLinkCriteria, acFormAdd, , Me.companyuid (where companyuid is the contact's company record).
    On the contact form I have the companyuid default value set to [OpenArgs]. (Note that even though I use the contact form as a subform elsewhere, the parent/child relationship takes precedent over the default value, so it's usable both ways.

    Now, here is what I can't figure out, I want the user to be able to add the information, and then on the close event pass back the contactuid for the newly created contact. Kind of an openargs in reverse.

    Any hints on how to do this?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a look at the form events in VB code window.. you will probably need touse the forms on close event. but better yet Id suggest you put a button ont he form that when clicked sends the data to the other form.

    eg in in frmContactMaster a button called cmdCloseForm
    the code in the cmdCloseForm on click event will be soemhtign like
    forms!frmServiceWorkOrder!<my destiantion control> = <my source control or varaible>

    eg
    forms!frmServiceWorkOrder!ContactUID = me.ContactUID
    HTH

  3. #3
    Join Date
    Oct 2003
    Posts
    103
    Thanks, I know how to do that one explicitly, but what I am hoping to do is create a "generic" kind of object oriented approach where I can call the contact form (or any other form) from multiple forms and have it return the value.

    Specifically, I might have multiple types of "contacts" on a single form such as (the primary contact, the secondary contact, the primary technician, the secondary technician, the PM technician), and also may need to assign contacts from multiple forms such as equipment, contracts, and as the subform for a customer's company.

    Because it does not make sense to create a special subform for each case, I want to be able to return the value . . .

    if this were a function rather than a form it would look something like
    private sub contact (companyuid as integer) as integer
    ' get the contactinformation
    contact=me.contactuid
    end sub

    or in c
    int contact(int companyuid)
    dim contactuid as int
    ' get the stuff
    return(contactuid)

    you get the idea

  4. #4
    Join Date
    Oct 2003
    Posts
    103
    Thanks, I know how to do that one explicitly, but what I am hoping to do is create a "generic" kind of object oriented approach where I can call the contact form (or any other form) from multiple forms and have it return the value.

    Specifically, I might have multiple types of "contacts" on a single form such as (the primary contact, the secondary contact, the primary technician, the secondary technician, the PM technician), and also may need to assign contacts from multiple forms such as equipment, contracts, and as the subform for a customer's company.

    Because it does not make sense to create a special subform for each case, I want to be able to return the value . . .

    if this were a function rather than a form it would look something like
    private sub contact (companyuid as integer) as integer
    ' get the contactinformation
    contact=me.contactuid
    end sub

    or in c
    int contact(int companyuid)
    dim contactuid as int
    ' get the stuff
    return(contactuid)

    my c is very rusty, but you get the idea

  5. #5
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    This is a little function I wrote to popup a custom InputBox:

    Code:
    Public Function GetDate(strMessage As String, _
                            booCancelled As Boolean) As Date
    
        
        DoCmd.OpenForm "frmEnterDate", acNormal, , , , acDialog, strMessage
        
        If Forms("frmEnterDate").Controls("chkCancelled") Then
        
            booCancelled = True
            GetDate = 0
            
        Else
        
            GetDate = Nz(Forms("frmEnterDate").Controls("txtDate"), 0)
            
        End If
        
        DoCmd.Close acForm, "frmEnterDate"
        
    End Function
    The keys to this code are, first you open the form using acDialog, by doing this, the calling code halts executing until the user closes the form. Next, you add a button to the form being called that HIDES the form when the user is done editting or adding data. Making the form invisible allows the code from the calling form to continue. Then you evaluate the changes or get the data you need from the form the user edited. And finally, the calling form closes the hidden form.

    You will see in the code, that I have a check box on the called form that is set to true when the user selects cancel. The button sets chkCancelled to true and then hides the form so that the calling code can continue.

  6. #6
    Join Date
    Oct 2003
    Posts
    103
    Thanks, that's interesting. I am not sure where you are hiding the form though unless it is getdate = 0?

    unless, of course, it's not in the function here, and it's just on the called form (me.visible=false). In that case, I think I understand.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •