473,327 Members | 2,112 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,327 software developers and data experts.

File Uploading

55
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....!
May 31 '07 #1
16 11176
puppydogbuddy
1,923 Expert 1GB
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:

http://www.mvps.org/access/api/api0001.htm

Browse and Open Files-free demo mdb with source code
http://www.candace-tripp.com/pages/access_downloads.aspx#8
May 31 '07 #2
Lebbsy
55
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.
May 31 '07 #3
Lebbsy
55
I managed to search the net and found the following code:

Private Sub cmdLoadOLE_Click()

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.RunCommand acCmdRecordsGoToNew
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.
May 31 '07 #4
puppydogbuddy
1,923 Expert 1GB
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
May 31 '07 #5
Lebbsy
55
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.
Jun 5 '07 #6
puppydogbuddy
1,923 Expert 1GB
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.
Jun 5 '07 #7
Lebbsy
55
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.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

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_Click()
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 "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
Jun 5 '07 #8
puppydogbuddy
1,923 Expert 1GB
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.
Jun 5 '07 #9
Lebbsy
55
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
Jun 5 '07 #10
puppydogbuddy
1,923 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, _
  5. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  6. Public Success As Boolean
  7.  
Jun 5 '07 #11
puppydogbuddy
1,923 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, _
  5. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  6. Public Success As Boolean
  7.  
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
Expand|Select|Wrap|Line Numbers
  1. Public Function Execute_Program(ByVal strFilePath As String, _
  2. ByVal strParms As String, ByVal strDir As String) _
  3. As Boolean
  4.  
Let me know what happens.
Jun 5 '07 #12
puppydogbuddy
1,923 Expert 1GB
Lebbsy,
Just so there is no misunderstanding, 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.
Expand|Select|Wrap|Line Numbers
  1. Public Function Execute_Program(ByVal strFilePath As String, _
  2. ByVal strParms As String, ByVal strDir As String) _
  3. As Boolean
  4.  
  5. 'run program
  6. Dim hwndProgram As Integer
  7. hwndProgram = ShellExecute(0, "Open", strFilePath, strParms, strDir, 3) '3 ==> Show Maximized
  8.  
  9. 'evaluate errors (if any)
  10. Select Case (hwndProgram)
  11. Case 0
  12. MsgBox "Insufficent system memory or corrupt program file.", 0, "Error running " & strFilePath
  13. Execute_Program = False
  14. Exit Function
  15. Case 2
  16. MsgBox "File not found.", 0, "Error running " & strFilePath
  17. Execute_Program = False
  18. Exit Function
  19. Case 3
  20. MsgBox "Invalid path.", 0, "Error running " & strFilePath
  21. Execute_Program = False
  22. Exit Function
  23. Case 5
  24. MsgBox "Sharing or Protection Error.", 0, "Error running " & strFilePath
  25. Execute_Program = False
  26. Exit Function
  27. Case 6
  28. MsgBox "Seperate data segments are required for each task.", 0, "Error running " & strFilePath
  29. Execute_Program = False
  30. Exit Function
  31. Case 8
  32. MsgBox "Insufficient memory to run the program.", 0, "Error running " & strFilePath
  33. Execute_Program = False
  34. Exit Function
  35. Case 10
  36. MsgBox "Incorrect Windows version.", 0, "Error running " & strFilePath
  37. Execute_Program = False
  38. Exit Function
  39. Case 11
  40. MsgBox "Invalid program file.", 0, "Error running " & strFilePath
  41. Execute_Program = False
  42. Exit Function
  43. Case 12
  44. MsgBox "Program file requires a different operating system.", 0, "Error running " & strFilePath
  45. Execute_Program = False
  46. Exit Function
  47. Case 13
  48. MsgBox "Program requires MS-DOS 4.0.", 0, "Error running " & strFilePath
  49. Execute_Program = False
  50. Exit Function
  51. Case 14
  52. MsgBox "Unknown program file type.", 0, "Error running " & strFilePath
  53. Execute_Program = False
  54. Exit Function
  55. Case 15
  56. MsgBox "Windows program does not support protected memory mode.", 0, "Error running " & strFilePath
  57. Execute_Program = False
  58. Exit Function
  59. Case 16
  60. MsgBox "Invalid use of data segments when loading a second instance of a program.", 0, "Error running " & strFilePath
  61. Execute_Program = False
  62. Exit Function
  63. Case 19
  64. MsgBox "Attempt to run a compressed program file.", 0, "Error running " & strFilePath
  65. Execute_Program = False
  66. Exit Function
  67. Case 20
  68. MsgBox "Invalid dynamic link library.", 0, "Error running " & strFilePath
  69. Execute_Program = False
  70. Exit Function
  71. Case 21
  72. MsgBox "Program requires Windows 32-bit extensions.", 0, "Error running " & strFilePath
  73. Execute_Program = False
  74. Exit Function
  75. Case Else
  76. End Select
  77.  
  78. Execute_Program = True
  79.  
  80. End Function
  81.  
Jun 5 '07 #13
Lebbsy
55
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.
Jun 6 '07 #14
puppydogbuddy
1,923 Expert 1GB
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.
Jun 6 '07 #15
Lebbsy
55
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.
I will try your suggestion, but can I insert a loop that will work as if I was pressing the CTRL key?
Jun 7 '07 #16
puppydogbuddy
1,923 Expert 1GB
I will try your suggestion, but can I insert a loop that will work as if I was pressing the CTRL key?
Yes, but I think you have to have a list box control with its multi-select property set to extended.
Jun 7 '07 #17

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

Similar topics

9
by: R. Rajesh Jeba Anbiah | last post by:
Q: How should I handle file upload? A: File uploading requires HTML form of content type "multipart/form-data". The file content has to be POSTed/submitted via the form and once the file is...
0
by: ¦è»P¦èµ^ | last post by:
Any homepage is for teaching file uploading in JAVA, JSP and TOMCAT, such as JSPSmartUpload? thx very much ~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ­n¯à©Ó¾á­·ÀI ~ ~ Samba, more than a low cost File and...
0
by: praba kar | last post by:
Dear All, I have doubt regarding file uploading. When we upload a file to the remote server we can get file type through file extentions. How we can find out file type if a file doesn't have...
1
by: psb | last post by:
WHO HAS THE BEST COMPONENT FOR FILE UPLOAD? HELP!? has anyone achieved 100% success with HTTP uploading with Mac clients??? I thought the whole <input type="file" .../> was a w3c standard that...
4
by: Mukesh | last post by:
Hi all I am trying to upload and save as a picture to "root/Photos" folder in my web application. I am using this code to perform this task DirectoryInfo strFolder = new...
1
by: ali | last post by:
I am writing a script which uploads file to a specific directory; I am using javascript to handle client side exceptions and php script which actually performs file uploading. Php scripts gets...
7
by: yatin.smile | last post by:
I am a fresher in php and java script. that's wy i join a group for do a discussion on different concepts of php and java scripts. now i m working on file uploading.So i need a discussion on this...
3
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
0
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted...
5
by: dmj07 | last post by:
Can anybody help me with a simple file uploading and retrieving idea? What I need is a simple system that uploads the files to be stored in a SQL database which are then shown on the front end in...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.