Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2006
    Posts
    126

    Unanswered: Call to Sub not working from event property

    I have a button on a form to call a subroutine.

    The sub is one that I wrote (actually plagiarized) similar to the following:

    Public Sub DoSomething(cancel as Integer)
    'lots of procedures'
    End Sub

    Incidently I started with Private and then tried Public. The Sub is in one of the modules that was in existance for the calling form.

    In the On Click property for the calling button, I put "=DoSomething()" without the quotes.

    I get the following error message when the button is clicked:
    The expression On Click you entered as the event property setting produced the following error: The expression you entered has a function name that Microsoft Access can't find. ...etc...

    I assume I'm missing something simple.
    Pete
    PGT

  2. #2
    Join Date
    Apr 2004
    Location
    metro Detroit
    Posts
    634
    This sub doesn't return a value so = won't work.

    Try just DoSomething or Call Dosomething.

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Change:
    Code:
    Public Sub DoSomething(cancel as Integer)
    to:
    Code:
    Public Function DoSomething(cancel as Integer)
    In the Onclick property, change to:
    Code:
    =DoSomething(False)
    Have a nice day!

  4. #4
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    994
    Provided Answers: 2
    Which version of Access are you using? Calling subroutines directly from Events doesn't work in Acc2010, as we have discovered to our cost.

    If you're sure it should work, the syntax involves brackets [] around the sub's name. Can't remember if the equals sign is also required, though.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

Tags for this Thread

Posting Permissions

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