Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Feb 2010
    Location
    Denver, CO
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with Variable (AXP (2002) SP-1)

    I am trying to trigger a function with the following code: <font color=blue>DoCmd.OpenFunction lstMailList.Value</font color=blue> . The <font color=blue>lstMailList.Value</font color=blue> variable is from a listbox that they user can choose from, which is in turn bound to the name of the function I am trying to trigger. When I run this code, I get an error stating that they function does not exist. The name of the function is corrrect (and even shows in the error message). There is no OpenProcedure method to use, or I would have used that one. I don't have much experience with Functions. Is there something I'm doing wrong??

    Here is the function I've created:

    <font color=blue>Public Function subML_Ridge()

    DoCmd.OpenQuery "qryML_HEC_DelTblML_Ridge"
    DoCmd.Close acQuery, "qryML_HEC_DelTblML_Ridge"
    DoCmd.OpenQuery "qryML_HEC2"
    DoCmd.Close acQuery, "qryML_HEC2"

    End Function</font color=blue>

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Problem with Variable (AXP (2002) SP-1)

    <<which is in turn bound to the name of the function I am trying to trigger.>>

    I may misunderstand, but are you trying to bind a control to the results of a function? In general that doesn't work unless you assign a value to the function before you exit. In this case your function would only run queries anyhow. You may also need to put an EQUAL sign before the name of the function in the Data Source property of the control. It would also help to understand what you want the user to see when they make a change in the value of the list box.
    Wendell

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Try Application.Run (AXP (2002) SP-1)

    Is the value in the listbox the name of the function you want to call? <font color=blue>lstMailList.Value</font color=blue> isn't a variable, it's a reference to the value of the listbox, so I assume that's what you meant. So would the item selected in the listbox be something like "subML_Ridge"? If so, you wouldn't do it using OpenFunction, which is for opening a function in a SQL Server database, not for running an Access routine. What you need is <font color=red>Application.Run</font color=red>, and you would write it like this:

    <pre> Application.Run(lstMailList.Value)</pre>


    Just keep in mind that if any of the listed functions require arguments, you have another problem.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    Feb 2010
    Location
    Denver, CO
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Try Application.Run (AXP (2002) SP-1)

    <font color=blue>Application.run</font color=blue> was the ticket. I wouldn't have thought <font color=blue>App.Run</font color=blue> would fire a Function. That's what love about this board--I just keep on learning!!! Thanks Charlotte!!

    Which brings me to a very good question. What reference would you recommend as a good primer for Access' Object Model? I have a few good books, but none of them detail how the Model hangs together. What do each of the <font color=blue>DoCmd</font color=blue> methods do? What else can <font color=blue>App.Run</font color=blue> do?? What other objects and methods are available that I don't even know about?

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Try Application.Run (AXP (2002) SP-1)

    The only reference book I know of that attempts to detail the object model is Helen Feddema's Programming the Access and DAO Object Model, although DAO isn't a hot topic at the moment, and it's based on Access 2000. See the reviews in the linked reference - they are quite mixed.
    Wendell

Posting Permissions

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