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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Problem with Variable (AXP (2002) SP-1)

    Author
    Topic
    #381994

    I am trying to trigger a function with the following code: DoCmd.OpenFunction lstMailList.Value . The lstMailList.Value 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:

    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

    Viewing 1 reply thread
    Author
    Replies
    • #646062

      <>

      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.

    • #646174

      Is the value in the listbox the name of the function you want to call? lstMailList.Value 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 Application.Run, and you would write it like this:

           Application.Run(lstMailList.Value)

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

      • #646849

        Application.run was the ticket. I wouldn’t have thought App.Run 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 DoCmd methods do? What else can App.Run do?? What other objects and methods are available that I don’t even know about?

        • #646852

          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.

    Viewing 1 reply thread
    Reply To: Reply #646062 in Problem with Variable (AXP (2002) SP-1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel