File Uploading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lebbsy
    New Member
    • May 2007
    • 55

    File Uploading

    I have three days trying to write a code that would help me upload several linked files (different extensions) to the access database and also be able to click on a single file and be able to view the file contents. Specfifically I want to upload pdf, doc, bmp, gif, jpg. Can anyone help me please....!
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by Lebbsy
    I have three days trying to write a code that would help me upload several linked files (different extensions) to the access database and also be able to click on a single file and be able to view the file contents. Specfifically I want to upload pdf, doc, bmp, gif, jpg. Can anyone help me please....!
    If by "uploading" , you mean the ability to browse to and open files from within your application, see these links:



    Browse and Open Files-free demo mdb with source code
    http://www.candace-tripp.com/pages/access_download s.aspx#8

    Comment

    • Lebbsy
      New Member
      • May 2007
      • 55

      #3
      Thanks for the reply. Yes I want to browse for files select files I consider relevant into a listbox and later enter them in the database. On viewing them in a report, I want to be able have the files listed and have an option of opening one of them to view its contents.

      Comment

      • Lebbsy
        New Member
        • May 2007
        • 55

        #4
        Uploading files to an access database

        I managed to search the net and found the following code:

        Private Sub cmdLoadOLE_Clic k()

        Dim MyFolder As String
        Dim MyExt As String
        Dim MyPath As String
        Dim MyFile As String
        Dim strCriteria As String

        MyFolder = Me!SearchFolder
        ' Get the search path.
        MyPath = MyFolder & "\" & "*." & [SearchExtension]
        ' Get the first file in the path containing the file extension.
        MyFile = Dir(MyPath, vbNormal)
        Do While Len(MyFile) <> 0
        [OLEPath] = MyFolder & "\" & MyFile
        [OLEFile].Class = [OLEClass]
        [OLEFile].OLETypeAllowed = acOLELinked
        [OLEFile].SourceDoc = [OLEPath]
        [OLEFile].Action = acOLECreateLink
        ' Check for next OLE file in the folder.
        MyFile = Dir
        ' Go to new record on form.
        DoCmd.RunComman d acCmdRecordsGoT oNew
        Loop

        End Sub

        What it does is, it lets you enter the file path,ole class name and file extensions then on pressing the Upload Files button it uploads all files of that extension to the database and display them one-at-a-time.

        My problem is making the files display as an icon-linked list and names associated with each link displayed underneath so that on clicking the icon it leads me to the associated file.

        Kind Regards.
        Last edited by Lebbsy; May 31 '07, 03:23 PM. Reason: Make one sentence clear

        Comment

        • puppydogbuddy
          Recognized Expert Top Contributor
          • May 2007
          • 1923

          #5
          Originally posted by Lebbsy
          My problem is making the files display as an icon-linked list and names associated with each link displayed underneath so that on clicking the icon it leads me to the associated file.

          Kind Regards.
          I think you would use the FollowHyperlink Method discussed in the link below. See if that meets your needs. If it doesn't let me know.

          http://msdn2.microsoft .com/en-us/library/aa221236(office .11).aspx

          Comment

          • Lebbsy
            New Member
            • May 2007
            • 55

            #6
            Originally posted by puppydogbuddy
            I think you would use the FollowHyperlink Method discussed in the link below. See if that meets your needs. If it doesn't let me know.

            http://msdn2.microsoft .com/en-us/library/aa221236(office .11).aspx
            On going through the other messages posted by other users, I came across a thread whose topic is "Retrieve filename from PDF OLE Object". This had exactly what I wanted to do but on running the code written there I came across this error:

            "The expression On Current you entered as the event property setting produced the following error: Constants, fixed-length strings, arrays, user-defined types, and Declare statements not allowed as Public members of object modules.
            * The expression may not result in the name of the macro, the name of the user-defined function, or [Event Procedure].
            * There may have been an error on evaluating the function, event or macro."

            Any idea of how to fix such errors? Please help me as I have been struggling for sometime now. I can post the code if you want.

            Thank you in advance.

            Comment

            • puppydogbuddy
              Recognized Expert Top Contributor
              • May 2007
              • 1923

              #7
              Originally posted by Lebbsy
              On going through the other messages posted by other users, I came across a thread whose topic is "Retrieve filename from PDF OLE Object". This had exactly what I wanted to do but on running the code written there I came across this error:

              "The expression On Current you entered as the event property setting produced the following error: Constants, fixed-length strings, arrays, user-defined types, and Declare statements not allowed as Public members of object modules.
              * The expression may not result in the name of the macro, the name of the user-defined function, or [Event Procedure].
              * There may have been an error on evaluating the function, event or macro."

              Any idea of how to fix such errors? Please help me as I have been struggling for sometime now. I can post the code if you want.

              Thank you in advance.
              Lebbsy,
              Don't struggle...let us know you still need help. It sounds your Public procedure is using the "Me" keyword, when a fully qualified object reference is required. Please post the code for the Form_Current event that is causing the problems. Thanks.

              Comment

              • Lebbsy
                New Member
                • May 2007
                • 55

                #8
                Originally posted by puppydogbuddy
                Lebbsy,
                Don't struggle...let us know you still need help. It sounds your Public procedure is using the "Me" keyword, when a fully qualified object reference is required. Please post the code for the Form_Current event that is causing the problems. Thanks.
                Here is the whole code. I have a a text box and a a button.

                Option Compare Database

                Declare Function ShellExecute Lib "shell32.dl l" Alias "ShellExecu teA" (ByVal hWnd As Long, ByVal lpOperation As String, _
                ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
                Public Success As Boolean

                Private Sub Form_Current()
                If IsNull(Me![txtFilePath]) Then
                Me!cmdViewFile. Enables = False
                Else
                Me!cmdViewFile. Enables = True
                End If

                End Sub

                Private Sub cmdViewFile_Cli ck()
                Success = Execute_Program (Me![txtFilePath], "", "")
                End Sub

                Public Function Execute_Program (ByVal strFilePath As String, _
                ByVal strParms As String, ByVal strDir As String) _
                As Boolean

                'run program
                Dim hwndProgram As Integer
                hwndProgram = ShellExecute(0, "Open", strFilePath, strParms, strDir, 3) '3 ==> Show Maximized

                'evaluate errors (if any)
                Select Case (hwndProgram)
                Case 0
                MsgBox "Insufficen t system memory or corrupt program file.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 2
                MsgBox "File not found.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 3
                MsgBox "Invalid path.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 5
                MsgBox "Sharing or Protection Error.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 6
                MsgBox "Seperate data segments are required for each task.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 8
                MsgBox "Insufficie nt memory to run the program.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 10
                MsgBox "Incorrect Windows version.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 11
                MsgBox "Invalid program file.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 12
                MsgBox "Program file requires a different operating system.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 13
                MsgBox "Program requires MS-DOS 4.0.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 14
                MsgBox "Unknown program file type.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 15
                MsgBox "Windows program does not support protected memory mode.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 16
                MsgBox "Invalid use of data segments when loading a second instance of a program.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 19
                MsgBox "Attempt to run a compressed program file.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 20
                MsgBox "Invalid dynamic link library.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case 21
                MsgBox "Program requires Windows 32-bit extensions.", 0, "Error running " & strFilePath
                Execute_Program = False
                Exit Function
                Case Else
                End Select

                Execute_Program = True

                End Function

                Comment

                • puppydogbuddy
                  Recognized Expert Top Contributor
                  • May 2007
                  • 1923

                  #9
                  Lebbsy,
                  Before I get into the code I need you to check for missing VB library file references. Go to the VB code editor, then select Tools> references. Do any references show as "Missing"?

                  Let me know. Thanks.

                  Comment

                  • Lebbsy
                    New Member
                    • May 2007
                    • 55

                    #10
                    Originally posted by puppydogbuddy
                    Lebbsy,
                    Before I get into the code I need you to check for missing VB library file references. Go to the VB code editor, then select Tools> references. Do any references show as "Missing"?

                    Let me know. Thanks.
                    None seems to be missing. I have all the Microsoft Office Type Libraries on, OLE Automation, Active X, PDFand the VBA

                    Comment

                    • puppydogbuddy
                      Recognized Expert Top Contributor
                      • May 2007
                      • 1923

                      #11
                      Originally posted by Lebbsy
                      None seems to be missing. I have all the Microsoft Office Type Libraries on, OLE Automation, Active X, PDFand the VBA
                      Lebbsy,
                      Your references are probably ok...otherwise you would see the word "Missing".

                      Re: your code,
                      Is the code below in a stand-alone module or is it behind a form code module? It should be in a stand-alone (Public) module. Also, you should use option explicit as shown.
                      Code:
                      Option Compare Database
                      Option Explicit
                      
                      Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, _
                      ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
                      Public Success As Boolean

                      Comment

                      • puppydogbuddy
                        Recognized Expert Top Contributor
                        • May 2007
                        • 1923

                        #12
                        Originally posted by puppydogbuddy
                        Lebbsy,
                        Your references are probably ok...otherwise you would see the word "Missing".

                        Re: your code,
                        Is the code below in a stand-alone module or is it behind a form code module? It should be in a stand-alone (Public) module. Also, you should use option explicit as shown.
                        Code:
                        Option Compare Database
                        Option Explicit
                        
                        Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, _
                        ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
                        Public Success As Boolean
                        Haven't heard back from you, but I think the following code also belongs with the other code in the stand-alone module. you can place it after the last line above
                        Code:
                        Public Function Execute_Program(ByVal strFilePath As String, _
                        ByVal strParms As String, ByVal strDir As String) _
                        As Boolean
                        Let me know what happens.

                        Comment

                        • puppydogbuddy
                          Recognized Expert Top Contributor
                          • May 2007
                          • 1923

                          #13
                          Lebbsy,
                          Just so there is no misunderstandin g, all the code for the Function Execute_Program through the End Function should be added to the standalone Public module discussed above, not just the first 3 lines.
                          Code:
                          Public Function Execute_Program(ByVal strFilePath As String, _
                          ByVal strParms As String, ByVal strDir As String) _
                          As Boolean
                          
                          'run program
                          Dim hwndProgram As Integer
                          hwndProgram = ShellExecute(0, "Open", strFilePath, strParms, strDir, 3) '3 ==> Show Maximized
                          
                          'evaluate errors (if any)
                          Select Case (hwndProgram)
                          Case 0
                          MsgBox "Insufficent system memory or corrupt program file.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 2
                          MsgBox "File not found.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 3
                          MsgBox "Invalid path.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 5
                          MsgBox "Sharing or Protection Error.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 6
                          MsgBox "Seperate data segments are required for each task.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 8
                          MsgBox "Insufficient memory to run the program.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 10
                          MsgBox "Incorrect Windows version.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 11
                          MsgBox "Invalid program file.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 12
                          MsgBox "Program file requires a different operating system.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 13
                          MsgBox "Program requires MS-DOS 4.0.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 14
                          MsgBox "Unknown program file type.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 15
                          MsgBox "Windows program does not support protected memory mode.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 16
                          MsgBox "Invalid use of data segments when loading a second instance of a program.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 19
                          MsgBox "Attempt to run a compressed program file.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 20
                          MsgBox "Invalid dynamic link library.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case 21
                          MsgBox "Program requires Windows 32-bit extensions.", 0, "Error running " & strFilePath
                          Execute_Program = False
                          Exit Function
                          Case Else
                          End Select
                          
                          Execute_Program = True
                          
                          End Function

                          Comment

                          • Lebbsy
                            New Member
                            • May 2007
                            • 55

                            #14
                            File Uploading

                            You do not have any idea how happy a person you made me today.... First of all let me apologise for taking too long to respond, maybe its because of our different time zones (+2 GMT this side) and because I can only access my project when I am at work.

                            The code works excellently, thanks for your patience all the way to the solution. I have a problem though, I have a button that when clicked opens the file Dialog box so that a user can choose a file to insert to the database. This works fine, the problem arises when I want to insert several files for one record into the the database. How can I go about doing that.

                            One again, thanx a lot.
                            Last edited by Lebbsy; Jun 6 '07, 12:58 PM. Reason: Make code readable

                            Comment

                            • puppydogbuddy
                              Recognized Expert Top Contributor
                              • May 2007
                              • 1923

                              #15
                              Originally posted by Lebbsy
                              You do not have any idea how happy a person you made me today.... First of all let me apologise for taking too long to respond, maybe its because of our different time zones (+2 GMT this side) and because I can only access my project when I am at work.

                              The code works excellently, thanks for your patience all the way to the solution. I have a problem though, I have a button that when clicked opens the file Dialog box so that a user can choose a file to insert to the database. This works fine, the problem arises when I want to insert several files for one record into the the database. How can I go about doing that.

                              One again, thanx a lot.
                              Lebbsy,
                              I am glad I could help. Regarding your multiple selection issue, I think all you need to do is hold the CTRL key down while you mouse click your selections. If it does not work that way, let me know.

                              Comment

                              Working...