How to execute mspaint and open a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cobolguy
    New Member
    • Sep 2008
    • 19

    How to execute mspaint and open a file

    I can execute mspaint using VBA but I have not been successful trying to open a .jpg image file. This command works to execute mspaint but I do not know how to excute and bring up a file at the same time. I am using Access 2007.

    Dim retVal
    retVal = Shell("c:\windo ws\system32\msp aint.exe", vbMaximizedFocu s)
  • aas4mis
    New Member
    • Jan 2008
    • 97

    #2
    Originally posted by cobolguy
    I can execute mspaint using VBA but I have not been successful trying to open a .jpg image file. This command works to execute mspaint but I do not know how to excute and bring up a file at the same time. I am using Access 2007.

    Dim retVal
    retVal = Shell("c:\windo ws\system32\msp aint.exe", vbMaximizedFocu s)
    All you need is the file location after your command.
    Code:
    Dim retVal
    retVal = Shell("c:\windows\system32\mspaint.exe c:\image.png", vbMaximizedFocus)

    Comment

    • Megalog
      Recognized Expert Contributor
      • Sep 2007
      • 378

      #3
      Are you dynamically opening different files with paint, or are you just trying to open one exact jpg?
      If the image isnt going to change, then you could code it in like shown above. But, if the path has any spaces in it you will need to put the entire filepath in quotes.

      If you're going to dynamically pass the file path to it, then use the following:
      Code:
      Dim retVal
      Dim strImgPath As String
      retVal = Shell("c:\windows\system32\mspaint.exe " & """" & strImgPath & _
          """", vbMaximizedFocus)
      That will ensure the proper quotes are inserted around the filepath.

      Comment

      • cobolguy
        New Member
        • Sep 2008
        • 19

        #4
        Appreciate the quick response. Still did not work. Paint comes up - but no image. Here is what I keyed:

        Dim retVal
        retVal = Shell("c:\windo ws\system32\msp aint.exe c:\CoronerDrawi ng.jpg", vbMaximizedFocu s)

        I made the path simple and can double click this file and it comes right up in Paint.

        Comment

        • cobolguy
          New Member
          • Sep 2008
          • 19

          #5
          Sorry guys - you were right. To the head of the class. I forgot I had used a macro instead of an event procedure. I am a little embarssed about that.
          Thanks. It worked.

          Here is the final work.

          Dim retVal
          Dim strImgPath As String
          '
          strImgPath = "c:\CoronerDraw ing.jpg"

          retVal = Shell("c:\windo ws\system32\msp aint.exe " & """" & strImgPath & _
          """", vbMaximizedFocu s)
          '

          Comment

          • Megalog
            Recognized Expert Contributor
            • Sep 2007
            • 378

            #6
            Glad to help!
            And your database already sounds way more interesting than the ones I work on.. with coroner drawings, etc =)

            Comment

            • cobolguy
              New Member
              • Sep 2008
              • 19

              #7
              I am writing a system for our Coroner. This is the first complete system I have done using Access and VBA. I am truly a Cobol guy :)

              Comment

              • missinglinq
                Recognized Expert Specialist
                • Nov 2006
                • 3533

                #8
                Originally posted by cobolguy
                I am writing a system for our Coroner. This is the first complete system I have done using Access and VBA. I am truly a Cobol guy
                Well, that's really appropriate! After all, Cobol really is a "dead" language!

                Linq ;0)>

                P.S. Sorry, but you just make it so darn easy to be cheesy!

                Comment

                • gardoglee
                  New Member
                  • Mar 2017
                  • 1

                  #9
                  Dead? Dead?

                  "Whoo-hoo-hoo, look who knows so much. It just so happens that your friend here is only MOSTLY dead. There's a big difference between mostly dead and all dead. Mostly dead is slightly alive."
                  Miracle Max


                  Originally posted by missinglinq
                  Well, that's really appropriate! After all, Cobol really is a "dead" language!

                  Linq ;0)>

                  P.S. Sorry, but you just make it so darn easy to be cheesy!

                  Comment

                  Working...