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....!
16 11176
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
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.
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.
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
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.
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.
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
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.
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
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. -
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
-
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. -
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 -
Public Function Execute_Program(ByVal strFilePath As String, _
-
ByVal strParms As String, ByVal strDir As String) _
-
As Boolean
-
Let me know what happens.
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. -
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
-
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.
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.
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
| |