• Advertisement
Sign in to follow this  

I don't understand this VBA error I'm getting.

This topic is 4367 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm just trying to write a function for an Access module that concatenates two strings together, and then uses the result as the pathname for a shell command. Here's what it looks like now:
Function ConvertWav2AT3()

Dim prjPath As String
Set prjPath = Environ$("PROJECT_PATH")

Dim shellPath As String
Set shellPath = "C:\program.exe -e _
      " & prjPath & "\src.foo c:\dest.foo"

Shell(shellPath, 1)

End Function
So you can see that "program.exe" takes on various arguments, including a destination file name and a source filename. The source file name depends on the person's PROJECT_PATH environment variable, and so I can't just set it here. I have to "concatenate" it into the source path. After typing in the Shell(shellPath, 1) function, I get an error that says:
Compile Error:
Expected: =
I have no idea what it's asking for. I though maybe it needed me to named the arguments, so I tried Shell(pathname:=shellPath, windowstyle:=1) and I still get the same error. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Which version of Access are you using? Different versions have different VBA versions that accept slightly different syntax.

Share this post


Link to post
Share on other sites
It's 2003. I was able to "fix" it by removing the parenthesis. I'm not sure why, though.

Share this post


Link to post
Share on other sites
Of course, now when I run the module, I get another error I don't understand:
Compiler error:
Object required

When I click "Ok", the "prjPath =" part of the Set statement is highlighted as though I've clicked and dragged the mouse over it. Also, the very first line of the code (with the function name) is highlighted in yellow.

I want to learn how to do this, but it's frustrating to run into these errors whenever I try to do the simplest thing.

Share this post


Link to post
Share on other sites
It probably doesn't like the Set on that line. Take it off.

Share this post


Link to post
Share on other sites
Thanks, that worked. Now it's telling me that my call to Shell is invalid at runtime. I took away the "1" argument. That worked and I'm not sure why. But thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement