0 votes
in VBA by Beginner (2 points)

I code a public sub in modules as same as :


Public Sub CallCalculator()

    AppActivate ("Microsoft Access")
    ' Specifying 1 as the second argument opens the application in
    ' normal size and gives it the focus.
    Dim RetVal
    Dim n
    RetVal = Shell("C:\WINDOWS\System32\CALC.EXE", 1)    ' Run Calculator.
    For n = 1 To 10
        SendKeys n & "{+}", True
    Next n
    SendKeys "=", True
    AppActivate "Microsoft Access"
    MsgBox "Select OK to escape Calculator"
    AppActivate "Calculator"
    SendKeys "%{F4}", True
    AppActivate "Microsoft Access"
End Sub

Access send a error message : Runtime error 5 Invalid procedure call or argument.

Need I config Tool/References in Access 2010?

1 Answer

0 votes
by Skilled (749 points)

In the VBA statement  AppActivate title the title part should be "the title in the title bar of the application window you want to activate." It is probably not "Microsoft Access", but it might be "Access". For example, when I first open Word the title bar is "Word", but when I open a blank document the title bar is "Document1 - Word". When I first open Excel the title bar is "Excel", but when I open a blank workbook the title bar is "Book1 - Excel". Also, notice the title in the title bar is duplicated in the Windows Taskbar.

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.


For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.