Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to open another application and several files

Status
Not open for further replies.

FrankMars

Technical User
Dec 20, 2010
67
US
I am an amateur with Access. I have a form based on a query. I open the form in datasheet view and use the filter function to narrow my result set. I then change to form view, which is continuous. I now see a list of records (usually 5-10) of which one field of each record contains a unique path to a corresponding file in another application. I would like to code a button which would open all the corresponding file paths of the result set in the other application. I tried to use the shell function and a loop but the closest I got was to open several instances of the other application and a file. Thank you in advance.
 
Which code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried to use the shell function and a loop ...
Again, with which code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry PH, here's the code I tried:

Private Sub Command29_Click()

Dim x As Variant
Dim Path As String
Dim File As String

Path = "C:\Program Files\Chief Architect\Chief Architect Premier X5 (64 bit)\Chief Architect Premier X5.exe"
File = [Text11] 'file path field

DoCmd.GoToRecord , , acFirst
Do While Me.CurrentRecord - 1 < Me.RecordsetClone.RecordCount
x = Shell(Path + " " + File, vbNormalFocus)
DoCmd.GoToRecord , , acNext
Loop

End Sub
 
Put this INSIDE the loop:
File = [Text11

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH - The other application and files open fine, but when I go back to Access I'm getting "Run-time error 94 - Invalid use of null". The continuous form shows focus in a blank new record at the bottom - I think this is the problem. Any suggestions?
 
Bracket your command with check for isnull:

If not isnull(File) then
x = Shell(Path + " " + File, vbNormalFocus)
End if

 
You might want to start using some typical abbreviations to id your fields and variables, names like "file" and "path" might kick off unexpected bugs because they mean things to other things you might not intend. I'd call the field 'file' txtFile, myself, and the variable 'path' as sPath because both file and path could be reserved words in some contexts. If you google "VBA field and variable pre-fixes" you'll get back some reading on the subject/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top