473,394 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to use a wildcard when opening an executable file with StrProg

I am using the following code to open up Acrobat Reader:
Expand|Select|Wrap|Line Numbers
  1. strProg = "C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe"
  2.  
which works fine, but on non-Windows7 computers the route is slighty different, also it is possible that a user may have an earlier version of Adobe. Is it possible to insert a wildcard in either or both of the 1st and 3rd directories to make display of a PDF independent of operating system and program version?

Nick
Oct 27 '10 #1

✓ answered by Oralloy

Nick,

When you are editing your VB code, there should be a "Project Explorer" window.

If not, you can show it by using the "View|Project Explorer" menu option.

It should show several folders, of which two are "Modules" and "Class Modules". You'll see your application's modules under these folders.

To create a new module, just right mouse ("click") anywhere in the window, and select the "Insert" option from the pop-up menu. From the "Insert" menu, you can insert a "Module" or "Class Module", depending on what you need todo.

Generally anything you insert will be given a generic (and fairly worthless) name like "Module1". You can change the name through the properties window.

If the properties window isn't showing, you can show it by using the "View|Properties Window" menu option.

BTW, my examples are often wordy, as I tend to build support skeletons around my code, or I steal some of my existing code and delete meat from the bones (the support skeleton). If you don't want the baggage, just remove it - after all, it's your code now, and I'm not proud.

Luck!

21 2857
Oralloy
988 Expert 512MB
Nick,

What would the system do, if it encountered conflicting versions of Acrobat on the system? Pick one, and hope it was the correct version?

You might look, instead, in the Windows registry under one of the adobe entries to find the current version.

On my system, I searched for acrobat and found the following handle, from which you might be able to extract the executable name.
Expand|Select|Wrap|Line Numbers
  1. HKEY_CLASSES_ROOT\acrobat\shell\open\command
Again, on later version Windows systems, if you want to display a .PDF (or other acrobat) file, and the "reader" is registered, you should be able to just "execute" the file, and the system will do the rest for you. Mind, I haven't tested this, but you might want to give it a quick test.

On non-windows systems, I'm not certain what you'll need to do.

Luck!
Oct 27 '10 #2
NeoPa
32,556 Expert Mod 16PB
If you'd like to access Registry Values from your database code there is some code for that available in Module to Read From the Windows Registry.
Oct 27 '10 #3
This routine opens Acrobat Reader and then the stored PDF of the invoice report applying to the selected record. As the paths to AcroRd32.exe vary (ie "\Program Files (x86)\" for Windows 7 and "\Program Files\" for XP and Vista) then I want the database to be able to function on different operating systems without the user having to amend the path to suit. Making the first directory (or even the last part of it) a wildcard would achieve that, if it's possible.
Oct 27 '10 #4
ADezii
8,834 Expert 8TB
I feel as though Oralloy had the right idea in Post #2. If your sole purpose is to Open *.pdf Files, and Adobe is the Registered Application for that File Type Extension (*.pdf), you can bypass executing the Adobe Executable and Execute the actual File or Path to the file itself. If you would like to see how this is done, just let me know.
Oct 27 '10 #5
Oralloy
988 Expert 512MB
Nick,

Were you using Perl, I'd say "glob the path"; however, this is in VBA.

You can still write the code to do path searches, but it's really not the happy way to go.

Also, there are folks (like me) who have tools mostly installed on a secondary "software" disk as part of their management technique.

So, if you're sticking with Windows systems, just execute the .PDF file. If you have to deal with Macintosh or Linux/Unix, then just execute the program name and trust that the user has his path set up correctly.

Cheers!
Oct 28 '10 #6
Thanks ADezii. Yes please!

Nick
Oct 28 '10 #7
NeoPa
32,556 Expert Mod 16PB
Nick,

It's not clear that you've read the two posts prior to your response. Certainly you seem to revert to a position which is incompatible with the information posted therein.

In post #2 it is made clear that using a wildcard would make no sense. You need to get your head around this before proceeding. It's not that we have no code for it. It simply makes no sense.

Moving to post #3, there is information there that will enable you to discover exactly where the executable is found by accessing the registry. Without the facility of a wildcard in the name (which we now know is a done deal), this appears to be the next logical step, assuming you bypass the even simpler one of simply executing the PDF file itself and relying on the PC's Association setup to find and execute the reader.

If there is something we are not aware of that makes this inappropriate for some reason, then you should share that (technically it should have been part of the original question of course). Merely repeating your original position as if no-one had responded already, just gives the impression you haven't bothered to read the replies.
Oct 28 '10 #8
ADezii
8,834 Expert 8TB
The Demo Code that I am going to post is the most basic, simplest, 4-step approach for Opening/Executing a File based solely on its Extension (*.XXX). Is you wish to expand on this basic concept, we can at a later time.
  1. Copy-N-Paste the following API Declaration into a 'Standard Code Module':
    Expand|Select|Wrap|Line Numbers
    1. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    2. ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    3. ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  2. Copy-N-Paste the following Code to wherever you deem appropriate:
    Expand|Select|Wrap|Line Numbers
    1. Dim strFile As String
    2. Dim lngErr As Long
    3.  
    4. 'Edit this:
    5. strFile = "C:\Dezii\KC Benefits.pdf"  ' the file you want to open/etc.
    6.  
    7. lngErr = ShellExecute(0, "OPEN", strFile, "", "", 0)
    8.  
    9. 'Optionally, add code to test Value of the lngErr Return Value
  3. Substitute your own Absolute Path to the *.pdf to be opened for "C:\Dezii\KC Benefits.pdf". This Value can be a Constant, Literal, pointer to a Control on your Form, etc.
  4. Execute the Code - The File specified in strFile will be opened.
  5. Any questions, feel free to ask.
Oct 28 '10 #9
Oralloy
988 Expert 512MB
Dezii,

Thanks for providing a good, working example. I think that'll get Nick over the hump for windows.
Oct 28 '10 #10
ADezii
8,834 Expert 8TB
Your welcome, at least for Windows! (LOL) Any non-Windows based OS, old Nick is on his own! (LOL)
Oct 28 '10 #11
Oralloy
988 Expert 512MB
Nahhh, not really

Expand|Select|Wrap|Line Numbers
  1. std::string command("acrobat ");
  2. command = command + "/usr/local/Oralloy/mydoc.pdf";
  3. system(command.c_str());
Oct 28 '10 #12
My apologies NeoPa, but you are attributing greater knowledge and experience to me than I merit. That is why it was not apparent to me prior to my #4 that the wildcard option was dead in the water. I know nothing about Registries and have alway been advised to steer clear of them if I'm not sure what I'm doing.

I did open up your recommended module in #3 but did not understand enough from it to proceed. Yes I should have replied to that effect but, as you no doubt gather, I'm new to these messaging systems and the protocol that applies, although I have every reason to be grateful for the things I have learned from this one (and you) so far.

I will hang slack for a day or two now and try to get my head around the further additions that have come along. For sure, executing the pdf directly is the way to go and many thanks to ADeziiall and Oralloy for their inputs too.
Regards - Nick
Oct 29 '10 #13
NeoPa
32,556 Expert Mod 16PB
A perfect response Nick :-)

For what it's worth, I think you've made a wise choice going with the associated application approach.

As for the Registry Reading code, and also the reliable advice you've received concerning playing with the registry, I would make two points that may help, and may even put things in a clearer perspective for you.
  1. The code linked to need not be understood to be used. Copy it wholesale into a module and it will be available to use, regardless of how it works. You would only need to understand how to call the RegRead() function. I've only just realised that I haven't explained that very well in the article and it could do with an update (Ooops).
  2. Reading Registry values is not dangerous. Updating them in any way is definitely to be avoided unless you really know what you're doing, but reading them is pretty harmless (I can't think of any scenario where that may cause any problem).

PS. The article has now been updated so may be more use for those previously couldn't even see where to start.
Oct 29 '10 #14
Thanks Oralloy. Are you saying that if I place this code directly into the class module for the form from which I want to be able to double-click the chosen record, it will execute the PDF? The path that I currently use is:
"C:\Wheelbase\Invoices\" & Me!Account & "-" & Me![Inv No] & ".pdf"
which you will note also imports two other variables from that record into the filename. How would that map into your middle line of code, forward slashes, etc?
Thanks
Nick
Oct 31 '10 #15
Oralloy
988 Expert 512MB
Nick,

Sorry for the long delay, I've been out of the office for the last three days.

Here is a bit of documentation on ShellExecuteA, that you might want to breeze through.

Anyway, I forgot this was a VBA forum when I posted my bit for Linux/Unix type systems.

So, to make a comprehensive windows solution (I am using Excel for testing), what I did was create a "Module" named "Code Test", which contained my test code, as follows:
Expand|Select|Wrap|Line Numbers
  1. ''====================================================================
  2. ''====================================================================
  3. ''====================================================================
  4. ''
  5. ''  Code Test
  6. ''    Module with various prepared code tests and use examples
  7. ''
  8. ''====================================================================
  9. ''====================================================================
  10. ''====================================================================
  11.  
  12.  
  13. Option Compare Database
  14. Option Explicit
  15.  
  16.  
  17. ''====================================================================
  18. ''====================================================================
  19. ''====================================================================
  20.  
  21. Public Sub TEST_showPDF()
  22.   Dim wi As Object
  23.   Set wi = New [Windoze Interface]
  24.   Call wi.showPDF("C:\tmp\IRON File Systems (vijayan-thesis).pdf")
  25. End Sub
  26.  
  27. '=====================================================================
  28. '=====================================================================
  29. '=====================================================================

And then, I created a "Class Module" with the actual launch code, as follows:
Expand|Select|Wrap|Line Numbers
  1. ''====================================================================
  2. ''====================================================================
  3. ''====================================================================
  4. ''
  5. ''  Windoze Interface
  6. ''    Code to interface to µsWindows DLLs
  7. ''
  8. ''====================================================================
  9. ''====================================================================
  10. ''====================================================================
  11.  
  12.  
  13. Option Compare Database
  14. Option Explicit
  15.  
  16.  
  17. ''====================================================================
  18. ''====================================================================
  19. ''====================================================================
  20.  
  21.  
  22. Private Type Body
  23.   database As DAO.database      ''--database object
  24.   databaseFile As String        ''--local database file
  25.  
  26.   EOL As String                 ''--end of line
  27.  
  28.   lastPDF As String             ''--last launched PDF file [diagnostic]
  29. End Type
  30.  
  31. Private Const moduleName = "Windoze Support"
  32.  
  33.  
  34. ''====================================================================
  35. ''====================================================================
  36. ''====================================================================
  37.  
  38.  
  39. Private this As Body
  40.  
  41.  
  42. ''====================================================================
  43. ''====================================================================
  44. ''====================================================================
  45.  
  46.  
  47. Private Declare Function ShellExecute _
  48.   Lib "shell32.dll" _
  49.   Alias "ShellExecuteA" _
  50.     (ByVal hwnd As Long, _
  51.      ByVal lpOperation As String, _
  52.      ByVal lpFile As String, _
  53.      ByVal lpParameters As String, _
  54.      ByVal lpDirectory As String, _
  55.      ByVal nShowCmd As Long) As Long
  56.  
  57.  
  58. ''====================================================================
  59. ''====================================================================
  60. ''====================================================================
  61.  
  62.  
  63. Private Sub Class_Initialize()
  64.   Set this.database = Application.CurrentDb
  65.   this.databaseFile = this.database.name
  66.   this.EOL = VBA.vbCrLf  'ASCII.CRLF
  67.   this.lastPDF = "<invalid>"
  68. End Sub
  69.  
  70.  
  71. Private Sub Class_Terminate()
  72.   'MsgBox ("Terminating module: " & moduleName)
  73. End Sub
  74.  
  75.  
  76. ''====================================================================
  77. ''====================================================================
  78. ''====================================================================
  79.  
  80.  
  81. Property Get databaseFile() As String
  82. ''
  83. ''  accessor for this.databaseFile
  84. ''
  85.   databaseFile = this.databaseFile
  86. End Property
  87.  
  88.  
  89. Property Let databaseFile(ByVal value As String)
  90. ''
  91. ''  accessor for this.databaseFile
  92. ''
  93.   this.databaseFile = value
  94. End Property
  95.  
  96.  
  97. Property Get lastPDF() As String
  98.   lastPDF = this.lastPDF
  99. End Property
  100.  
  101.  
  102. ''====================================================================
  103. ''====================================================================
  104. ''====================================================================
  105.  
  106.  
  107. Public Sub showPDF(ByVal fileName As String)
  108. ''
  109. ''  shows the given PDF file using acrobat
  110. ''
  111. ''  inputs:
  112. ''    fileName - fully qualified file name to show
  113. ''               (ex: C:/tmp/my.PDF)
  114. ''  raises:
  115. ''    true  - unqualified success
  116. ''    false - otherwise
  117. ''
  118.   ''--local variables and definitions
  119.   Dim pdf As String
  120.   Dim run As Boolean
  121.   Dim seResult As Long
  122.  
  123.   ''--initialize
  124.   pdf = fileName
  125.   run = True
  126.  
  127.   ''--slight diagnostic here...
  128.   this.lastPDF = fileName
  129.  
  130.   ''--attempt liftoff
  131.   If (run) Then
  132.     seResult = ShellExecute(0, "OPEN", pdf, "", "", 0)
  133.  
  134.     If (32 >= seResult) Then
  135.       run = False
  136.       Err.Raise 0, moduleName, "ShellExecute failed with code: " & seResult
  137.     End If
  138.   End If
  139.  
  140.   ''--end of compilation unit with implicit return
  141. End Sub
  142.  
  143.  
  144. ''====================================================================
  145. ''====================================================================
  146. ''====================================================================
IMPORTANT: the first is a "Module", and the second a "Class Module".

Then, in the "Immediate" window of the VBA interface window, I typed the following to demonstrate my code launch.
Expand|Select|Wrap|Line Numbers
  1. CALL [Code Test].TEST_showPDF
I sure hope this helps.

Luck!
Nov 1 '10 #16
Thanks Oralloy and ADezii, for spending your valuable time on this. My problem (or at least one of them!) is that I really don't understand how and where to put this code. I am using Access 2007 and enter code by going into form design and then 'view code' so whilst I can generate code in 'Class' modules, I'm not clear on where to create a Standard Module, which I guess is why I had no joy with your suggestion at #9, ADezii. It just stopped me opening the form with the error 'No Current Record'. This is the code I used:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
  2. ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
  3. ByVal lpParameters As String, ByVal lpDirectory As String, ByVal ShowCmd As Long) As Long
  4.  
  5. Option Compare Database
  6.  
  7. Private Sub Form_DblClick(Cancel As Integer)
  8. Dim strFile As String
  9. Dim lngErr As Long
  10. strFile = "C:\Wheelbase\Invoices\" & Me!Account & "-" & Me![Inv No] & ".pdf"  
  11. lngErr = ShellExecute(0, "OPEN", strFile, "", "", 0)
  12.  
Unless you can see an obvious problem then I think it's only fair on you both that I do some more reading up before I waste any more of your time.
Nick
Nov 2 '10 #17
Oralloy
988 Expert 512MB
Nick,

When you are editing your VB code, there should be a "Project Explorer" window.

If not, you can show it by using the "View|Project Explorer" menu option.

It should show several folders, of which two are "Modules" and "Class Modules". You'll see your application's modules under these folders.

To create a new module, just right mouse ("click") anywhere in the window, and select the "Insert" option from the pop-up menu. From the "Insert" menu, you can insert a "Module" or "Class Module", depending on what you need todo.

Generally anything you insert will be given a generic (and fairly worthless) name like "Module1". You can change the name through the properties window.

If the properties window isn't showing, you can show it by using the "View|Properties Window" menu option.

BTW, my examples are often wordy, as I tend to build support skeletons around my code, or I steal some of my existing code and delete meat from the bones (the support skeleton). If you don't want the baggage, just remove it - after all, it's your code now, and I'm not proud.

Luck!
Nov 2 '10 #18
ADezii
8,834 Expert 8TB
The best thing that I can do at this point is to create a simple Demo for you, parallelling your situation as much as possible. In this manner, you can see exactly what is going on, and how it is accomplished. I'll have one for you in a day or two. Stay tuned...

Scratch the above! I just created a Demo for you in World Record Time.
  1. Download the Attachment
  2. Copy the *.pdf Files to the C:\Wheelbase\Invoices\ Directory
  3. Open the Demo Database
  4. There are 3 Dummy Records, click on the Command Button to Open any 1 of the 3 corresponding .pdfs
  5. Play with the Code, and if you have any questions, please feel free to ask.
Attached Files
File Type: zip OpenPDF.zip (73.4 KB, 106 views)
Nov 3 '10 #19
Bravo! Oralloy, your advice on where to put a standard module has enabled me to use ADezii's original code in #9 which now works a treat. Sorry A for the extra work you put in last night. This question about standard modules has baffled me for many months despite searching high and low in Access Help for advice. So I am most grateful to you both for solving this particular problem and must divide the credit equally. Is it allowed for me to tick 'best answer' for both of you? Thanks also to NeoPa for his inputs along the way, which I am now better equipped to take on board.
Cheers
Nick
Nov 3 '10 #20
ADezii
8,834 Expert 8TB
Oralloy deserves most of the credit, kindly allot him the Best Answer.
Nov 3 '10 #21
NeoPa
32,556 Expert Mod 16PB
ADezii is generous to a fault. It's a long term affliction he's had since I first knew him :-D

@Nick:
Anyway, it's quite gratifying to see how much you've progressed in a single thread. Good for you :-)

PS. I'm afraid it's not possible to assign Best Answer to more than one post. I know both have been very helpful, but I suggest you look at the original question, and try to determine which single post goes furthest towards answering that. Think in terms of others following in your footsteps and wanting an answer for a similar problem.
Nov 4 '10 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: KS | last post by:
I have a class file, A, that inherits a SpecPanel that inherits Panel. When I try to open A in I gets an error: A red cross and a some text and something about "Constructor on type...
1
by: Scott Chang | last post by:
Hi all, I loaded the following program 'HelloMCPP' to my MS VC++ .NET (2002) that is installed on my Windows XP Professional PC: ------------------------------------- AssemblyInfo.cpp...
1
by: Mullin Yu | last post by:
I want to open a file by the native application without opening the Dialog Box asking "Open, Save or Cancel" . I know I can do at the client workstation by selecting the registry. But, I don't...
1
by: Mark | last post by:
Hello I was hoping to appeal to the gurus of the audience that may be able to contribute to resolving my problem I built a web reporting website in .NET using Crystal (God help me!) but I've...
3
by: SpIcH | last post by:
Hi All, This is all about protecting my data in Executable file. I have developed a program in Visual Basic .NET 2002. I have many questions in mind... please help me to complete my project. ...
3
by: Dan W | last post by:
Hi there. I am parsing a text file and as I parse each line I need to go out to two different directories and check to see if any files beginning with the string I just parsed exist. For...
8
by: Claudio Grondi | last post by:
Here an example of what I mean (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte large file): Traceback (most recent call last): File "<pyshell#1>", line 1, in -toplevel-...
1
by: Lucvdv | last post by:
In my assembly.vb files, I'm using the revision/build wildcard style: <Assembly: AssemblyVersion("3.0.*")> <Assembly: AssemblyFileVersion("3.0.*")> This onkly seems to work in projects that...
8
by: Lonifasiko | last post by:
Hi, Using Process class I asynchronously launch an executable (black box executable) file from my Windows application. I mean asynchronously because I've got an EventHandler for "Exited" event....
3
by: blerina | last post by:
hi, i have a simple asp code that opens an excel file. it works fine with simple excel files that don't contain formula. i think the problem is that my excel file contains formulas and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.