Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:37:12+00:00 2026-05-25T19:37:12+00:00

I am trying to run a Stored MS-access Query from excel using VBA. I

  • 0

I am trying to run a Stored MS-access Query from excel using VBA. I have created a generic function to preform this task (using ADODB). I can get results with or without parameters.

However when I try to run a stored Query that references an Access vba module, excel barfs a runtime error “undefined function MissCat” (which is the name of the custom function the stored query uses).

I would have expected this to work as access knows the definition of the function, but now I get the feeling the ADODB interface is trying to interperet the SQL in the stored query without the aid of the VBA module i’ve created in access.

I am jumping through these hoops as most of my users do not have access installed on their machines.

Is it possible for me to use the stored query as is (changing the query interface, perhaps)? or is the path of least resistance changing the query such that it doesn’t need the custom function (as you can see below it is quite simple, I’ve used it as a crutch because I don’t know SQL very well)

here is the function

Function MissCat(ProShip As Date, TargetDate As Date) As String

If TargetDate >= ProShip Then
    MissCat = "Meets target"
    Exit Function
End If

If TargetDate < Date Then
    MissCat = "Unrecoverable"
    Exit Function
End If

Select Case ProShip - TargetDate
    Case 1 To 6
        MissCat = "Less than one week"
    Case 7 To 14
        MissCat = "1-2 Weeks"
    Case Else
        MissCat = "Greater than 2 Weeks"
End Select
End Function

and here is the SQL

TRANSFORM Count(Shipset.ID) AS CountOfID
SELECT Calendar.[Week Of]
FROM Calendar INNER JOIN Shipset ON Calendar.DateSerial = Shipset.ShipDate
WHERE (((Calendar.[Week Of])>Date()-(13*7)) AND ((Shipset.ShipDate) Is Not Null) AND   ((Shipset.ReqOut)=False) AND ((Shipset.TwoTier)=False))
GROUP BY Calendar.[Week Of]
ORDER BY IIf(MissCat([Shipset]![ShipDate],[Shipset]![TargetDate])="Meets Target","Meets Target","Hit") DESC 
PIVOT IIf(MissCat([Shipset]![ShipDate],[Shipset]![TargetDate])="Meets Target","Meets Target","Hit");

thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:37:13+00:00Added an answer on May 25, 2026 at 7:37 pm

    Your query will not be able to use the custom VBA function except when it is run from within an Access session.

    You can substitute nested IIf() function statements for the MissCat function. Two challenges with that approach when the nesting is complex: it’s hard to follow the logic; it’s easy to screw up the syntax.

    The general form is IIf(condition, truepart, falsepart)

    So for the first condition, try this in a temporary procedure you create in Access.

    Debug.Print IIf(TargetDate >= ProShip, "Meets target", "else")
    

    As the next step, replace “else” with an IIf expression for the second condition.

    Debug.Print IIf(TargetDate >= ProShip, "Meets target", _
        IIf(TargetDate < Date, "Unrecoverable", "else"))
    

    And so forth. This is what I wound up with as the final grand mess.

    Debug.Print IIf(TargetDate >= ProShip, "Meets target", _
        IIf(TargetDate < Date, "Unrecoverable", _
        IIf(ProShip - TargetDate < 7, "Less than one week", _
        IIf(ProShip - TargetDate < 15, "1-2 Weeks", "Greater than 2 Weeks"))))
    

    After you have the procedure working correctly, copy the nested IIf expression and test it in a new Access query.

    SELECT
        ProShip,
        TargetDate,
        IIf(TargetDate >= ProShip, "Meets target", 
        IIf(TargetDate < Date, "Unrecoverable", 
        IIf(ProShip - TargetDate < 7, "Less than one week",
        IIf(ProShip - TargetDate < 15, "1-2 Weeks", "Greater than 2 Weeks")))) AS MissCat 
    FROM YourTable;
    

    After looking again at how you used the MissCat function in your original query, I don’t think I’d try to substitute this approach directly. I would create a separate query to transform the base data and then adapt the original query to use the new query as one of its data sources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run a batch file, as another user, from my web app.
I'm trying to run a LINQ to SQL query that returns a result in
I'm trying to run some commands in paralel, in background, using bash. Here's what
I have the unfortunate task of having to import data from excel into a
I'm trying to read data stored in a ms access database that generated by
I am trying to run the VS 2008 SP1 installer , but it says
I'm trying to run some queries to get rid of XSS in our database
I'm trying to run a process and do stuff with its input, output and
I'm trying to run the Tomcat with JBoss Embedded jpa booking example. I run
I'm trying to run SQuirreL SQL. I've downloaded it and installed it, but when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.