• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Using the focus to concatenate argument for the Call Shell function

How can I use the focus to concatenate argument for the Call Shell function?

I can use it to compare it to a string of a file
name that the focus is on a string field of a form
but I cant concatenate the return value with another
string to get it run the shell function.
I do not want to code a bunch of ifs or use a loop
to go through entries in the table that contains the
name of the file so it will run the shell function.
I need the use the name that returns from the focus
after a user pushes the command button to launch this
program and open the file passed to it by the focus,
(sort of like typing in the DOS world c:\aclt.exe filename).

below is the code that works to compare and launch the file
if the focus returns the proper filename. I have coded a
bunch of ifs to check against which file the focus returns
using this method but this is not practicle for adding
new filenames to the database.

Sub btnEditDrawing_Click()
On Error GoTo Err_btnEditDrawing_Click

    Dim stAppName As String
    If strFileName = "LEVELSUB.DWG" Then
        stAppName = "C:\ACLTWIN\ACLT.EXE C:\WORK\Meridien\LEVELSUB.DWG"
        Call Shell(stAppName, 1)
    End If
    If IsNull(strFileName) Then
        DoCmd.OpenForm "dglFileError", acNormal
    End If

    Exit Sub

    MsgBox Err.Description
    Resume Exit_btnEditDrawing_Click
End Sub

What I want is something like this in psuedo code:
        stAppName = "C:\ACLTWIN\ACLT.EXE C:\WORK\Meridien\"&[SetFocus]
'The above should work but doesn't as something is not being translated right and I dont know what
        Call Shell(stAppName, 1)
  • 5
  • 3
1 Solution
How do you know which program the user wants to launch? Are they choosing from a list of programs, or . . .?

It sounds like you might want to have a list or combo box with two columns: one with a name the user will recognize, and the other with the file path. Then when they click a button to launch the app they chose in the list/combo box, you could just use the list box value in your Shell function. That would also make it easier in the future when apps are added to your database: a simple addition to the Apps table would automatically be accommodated.

Would that work in your situation?

lskelleyAuthor Commented:
No I do not want  a combo box as the user is using a form that is already displaying
the name of the file and the focus is already on the name of the file. When the button
is pressed the above code executes. My problems is trying to get the string return
from the focus to work as a concatenated string with
"C:\ACLTWIN\ACLT.EXE C:\WORK\"& here I place SetFocus which doesn't

lskelleyAuthor Commented:
forgot to add that the only program I want to launch for this app is acltwin.exe in the
string above. The user has no choice of that, only which file it will open at run time
which comes from the focus of the filename in the form.
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

lskelleyAuthor Commented:
Edited text of question
I'm a little confused about one thing: you keep referring to returning the name of the file from the focus. The focus is simply where the computer is looking at this time. You can set the focus/cursor somewhere, but you can't "return" anything from the focus. How does the user tell you which file s/he wants. Below, I'm making the assumption that the user has entered the file name in a text box; the syntax would be the same if you were using list/combo boxes.

So the user types/chooses the file name (not the app) and you need to concatenate that file name with the file path to the app and then the directory, etc.? Is it always going to come from the same directory? If so, you could do this:

strAppName = "C:\ACLTWIN\ACLT.EXE C:\WORK\Meridien\" & [TheNameOfYourTextBox]

then do your shell function. Would that work?

lskelleyAuthor Commented:
I obviously was under the mistaken impression that the focus was returning
the the information now from reading your comments I see that what I need
to talk about is the value strFileName is returning.

The user is not necessarily typing in the file name it could already be put
there from the table the form is working on. If you use the line of code such
as you have shown, (modified to fit my app):

strAppName="C:\ACLTWIN\ACLT.EXE C:\WORK\Meridien\" & [strFilename]

It works!

Thank you!

It shows me that I need to improve my communication skills to where I need to
understand the problem thoroughly before posting such a question!

If you submit it as an answer I will let you have the points as this was
giving me a headache and I should known better! (It was a late night and
I was getting deperate to show this database to someone).
lskelleyAuthor Commented:
Oh by the way can you tell me where to find out how to give you the points and lock
this question I am brand new to this message board.


Now that I've submitted an answer, you can simply accept it (and grade it) and I'll get the points. Thank *you*, and I'm glad your problem is solved.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now