Results 1 to 6 of 6

Thread: Passing document argument to form load sub

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Passing document argument to form load sub

    Hi everyone!

    I have the following sub in a class module, and i want to pass the DocumentObject argument to a form load sub, How can i do this?
    thanks.

    *******Class module ****************

    Private Sub MyAppEV_OnCloseDocument( _
    ByVal DocumentObject As Document, _
    ByVal FullFileName As String, _
    ByVal BeforeOrAfter As EventTimingEnum, _
    ByVal Context As NameValueMap, _
    ByRef HandlingCode As HandlingCodeEnum _
    )


    Msgbox "the document name is "&DocumentObject

    End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Passing document argument to form load sub

    In another form?

    VB Code:
    1. '[In a Module]
    2. Public MyDocumentObject As Document
    3.  
    4. '[In your sub]
    5. Private Sub MyAppEV_OnCloseDocument( _
    6. ByVal DocumentObject As Document, _
    7. ByVal FullFileName As String, _
    8. ByVal BeforeOrAfter As EventTimingEnum, _
    9. ByVal Context As NameValueMap, _
    10. ByRef HandlingCode As HandlingCodeEnum _
    11. )
    12.  
    13. '...
    14.  
    15. MyDocumentObject = DocumentObject
    16.  
    17. '[In your other form]
    18. Private Sub Form_Load()
    19. MsgBox "the document name is " & MyDocumentObject

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Passing document argument to form load sub

    HI,AI42, i did not understand your reply.

    ok i have the following sub in a class module
    and when i call the form1 in the class module, i want to acess the DocumentObject argument of the class module inside of the form load sub?

    i hope you will understand this, Thanks?


    *********Class module****
    Private Sub MyAppEV_OnCloseDocument( _
    ByVal DocumentObject As Document, _
    ByVal FullFileName As String, _
    ByVal BeforeOrAfter As EventTimingEnum, _
    ByVal Context As NameValueMap, _
    ByRef HandlingCode As HandlingCodeEnum _
    )


    Msgbox "the document name is "&DocumentObject

    form1.show

    End Sub

  4. #4
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: Passing document argument to form load sub

    You can't pass anything directly into the Load event, but you can pass it to the form before the Load event so that it'll be there when the form is loaded:
    VB Code:
    1. ' *** CLASS MODULE ***
    2.  
    3. Private Sub MyAppEV_OnCloseDocument( _
    4. ByVal DocumentObject As Document, _
    5. ByVal FullFileName As String, _
    6. ByVal BeforeOrAfter As EventTimingEnum, _
    7. ByVal Context As NameValueMap, _
    8. ByRef HandlingCode As HandlingCodeEnum _
    9. )
    10.   Dim frm As Form1
    11.  
    12.  
    13.   'Create the form, but don't load it.
    14.   Set frm = New Form1
    15.  
    16.   'Pass a reference to the document to the form.
    17.   Set frm.DocumentObject = DocumentObject
    18.  
    19.   'Load & show the form.
    20.   frm.Show
    21. End Sub


    VB Code:
    1. ' *** FORM CODE ***
    2.  
    3. Public DocumentObject As Document
    4.  
    5. Private Sub Form_Load()
    6.   MsgBox "Document name: " & DocumentObject
    7. End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Passing document argument to form load sub

    Thanks bpd.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Passing document argument to form load sub

    Quote Originally Posted by em07189
    HI,AI42, i did not understand your reply.

    ok i have the following sub in a class module
    and when i call the form1 in the class module, i want to acess the DocumentObject argument of the class module inside of the form load sub?
    You can do it the way em07189 showed you or you can make the value available in a global variable the way I showed you, so any part of the program can access it. Depending on what you're doing, sometimes it's more efficient one way, sometimes the other. And sometimes it doesn't matter.

Posting Permissions

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



Click Here to Expand Forum to Full Width