Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can i pass the name of the form (Access 2000)

    I want to make a function that should be valid for all forms in the database. Therefore i have put the following in the brackert:
    (frm As Form)

    After that in my function i use the following expressions:
    Forms!frm![MyControl] etc etc

    My function looks something like that:
    Public Function CancelAnniversary (frm As Form)

    ......do something

    End Function


    In the OnClick event in my forms i i write :
    CancelAnniversary(Me)

    However i receive the error type mismatch.Can somebody explain to me why do i receive this error ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can i pass the name of the form (Access 2000)

    You don't need to use Forms!frm![MyControl]. Just frm![MyControl] should work.

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: How can i pass the name of the form (Access 2000)

    If you want this to be valid for all forms in your database, why not pass the control instead of the form? Like this:

    Public Function CancelAnniversary (ctl as control)

    ......do something

    End Function
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: How can i pass the name of the form (Access 2000)

    Hi,
    In addition to the other points, you also need to use the syntax:
    CancelAnniversary Me
    or
    Call CancelAnniversary(Me)
    Your original syntax is not passing the form as an object to the function, it's passing the default property of the form - i.e. its controls.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: How can i pass the name of the form (Access 2000)

    You could bypass the need for a parameter altogether this way if you always want the function to apply to the active form

    public function fnCancelAnniversary()

    Screen.activeform![mycontrol]etc
    end function

    then you can call it as just fnCancelAnniversary
    Regards
    John



Posting Permissions

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