473,387 Members | 1,364 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,387 software developers and data experts.

View/edit files of various file types within Access window

imrosie
222 100+
Hello,
I am attempting to build a form that allows for veiwing files (txt, doc, rtf, xls, pdf) within a subform. I need to have ability to browse to any directory, pull up a file in the subform 'Window', edit that file within the window (and save) then also 'add each path into the datatbase for . I don't want to use absolute paths because there will be too many users with various mapped folders

I saw one discussion (from ADezii) with a promising solution except for the "Absolute Path". Because of the absolute path (which I don't require), the button is grayed out. I need to ability to 'select' a file first . Has anyone altered that solution to do this??? If so, could you post that code??

thanks
Rosie
Jun 19 '07 #1
16 2887
ADezii
8,834 Expert 8TB
Hello,
I am attempting to build a form that allows for veiwing files (txt, doc, rtf, xls, pdf) within a subform. I need to have ability to browse to any directory, pull up a file in the subform 'Window', edit that file within the window (and save) then also 'add each path into the datatbase for . I don't want to use absolute paths because there will be too many users with various mapped folders

I saw one discussion (from ADezii) with a promising solution except for the "Absolute Path". Because of the absolute path (which I don't require), the button is grayed out. I need to ability to 'select' a file first . Has anyone altered that solution to do this??? If so, could you post that code??

thanks
Rosie
  1. What is the mechanism by which you are Viewing/Editing a File in the Sub-Form?
  2. Even if you don't require the Absolute Path to the selected File in your Database, you will surely need it to Open the file.
  3. There have been many examples in this Forum relating to the File Dialog Box, and other similar Browsing methods (Windows Dialog, API, etc.), but inevitably they all return a Path to the File.
Jun 19 '07 #2
imrosie
222 100+
  1. What is the mechanism by which you are Viewing/Editing a File in the Sub-Form?
  2. Even if you don't require the Absolute Path to the selected File in your Database, you will surely need it to Open the file.
  3. There have been many examples in this Forum relating to the File Dialog Box, and other similar Browsing methods (Windows Dialog, API, etc.), but inevitably they all return a Path to the File.
Hi ADezii,

Actually I'm trying to add a form to the image database, then have the switchboard open either documents or images. So I already had in there some of your declaration code:
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

There is some 'Open Dialog' code there too (used for the images), sorry it's pretty long:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. ' Code to display standard "Open File" dialog.
  5.  
  6. Type OPENFILENAME
  7.   lStructSize As Long
  8.   hwndOwner As Long
  9.   hInstance As Long
  10.   lpstrFilter As String
  11.   lpstrCustomFilter As String
  12.   nMaxCustFilter As Long
  13.   nFilterIndex As Long
  14.   lpstrFile As String
  15.   nMaxFile As Long
  16.   lpstrFileTitle As String
  17.   nMaxFileTitle As Long
  18.   lpstrInitialDir As String
  19.   lpstrTitle As String
  20.   flags As Long
  21.   nFileOffset As Integer
  22.   nFileExtension As Integer
  23.   lpstrDefExt As String
  24.   lCustData As Long
  25.   lpfnHook As Long
  26.   lpTemplateName As String
  27. End Type
  28.  
  29. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
  30.   "GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean
  31.  
  32. Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
  33.   "GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean
  34.  
  35. Private Const ALLFILES = "All files"
  36.  
  37. Function MakeFilterString(ParamArray varFilt() As Variant) As String
  38. ' Create filter string.
  39. ' Returns "" if there are no arguments.
  40. ' Expects an even number of arguments (filter name, extension).
  41. ' Adds *.* if the number of arguments is odd.
  42.  
  43.   Dim strFilter As String
  44.   Dim intRes As Integer
  45.   Dim intNum As Integer
  46.  
  47.   intNum = UBound(varFilt)
  48.   If (intNum <> -1) Then
  49.     For intRes = 0 To intNum
  50.       strFilter = strFilter & varFilt(intRes) & vbNullChar
  51.     Next
  52.     If intNum Mod 2 = 0 Then
  53.       strFilter = strFilter & "*.*" & vbNullChar
  54.     End If
  55.  
  56.     strFilter = strFilter & vbNullChar
  57.   End If
  58.  
  59.   MakeFilterString = strFilter
  60. End Function
  61.  
  62. Private Sub InitOFN(OFN As OPENFILENAME)
  63.   With OFN
  64.     ' Initialize fields user doesn't want to know about
  65.     .hwndOwner = hWndAccessApp
  66.     .hInstance = 0
  67.     .lpstrCustomFilter = vbNullString
  68.     .nMaxCustFilter = 0
  69.     .lpfnHook = 0
  70.     .lpTemplateName = 0
  71.     .lCustData = 0
  72.     .nMaxFile = 511
  73.     .lpstrFileTitle = String(512, vbNullChar)
  74.     .nMaxFileTitle = 511
  75.     .lStructSize = Len(OFN)
  76.     ' Use default filter if not specified.
  77.     If .lpstrFilter = "" Then
  78.       .lpstrFilter = MakeFilterString(ALLFILES)
  79.     End If
  80.     ' Pad lpstrFile with null chars.
  81.     .lpstrFile = .lpstrFile & String(512 - Len(.lpstrFile), vbNullChar)
  82.   End With
  83. End Sub
  84.  
  85. Function OpenDialog(OFN As OPENFILENAME) As Boolean
  86.   Dim intRes As Integer
  87.   InitOFN OFN
  88.   intRes = GetOpenFileName(OFN)
  89.   If intRes Then
  90.     ' Remove trailing null chars from lpstrFile.
  91.     With OFN
  92.       .lpstrFile = Left$(.lpstrFile, InStr(.lpstrFile, vbNullChar) - 1)
  93.     End With
  94.   End If
  95.   OpenDialog = intRes
  96. End Function

I was thinking I could add your code "Public Success As Boolean" to the Declaration module; add the function:
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
(as you suggested to Steve123) then I would have most of what I needed???


I'm not real clear on which mechanism to use for the viewing. for pdf's, Adobe, for .doc's, Word...etc. is that what you're referring to?
The problem is the graying out of the the cmdbutton you use.....until there's an absolute path. That's the part I'm trying to figure out. thanks

Rosie
Jun 19 '07 #3
NeoPa
32,556 Expert Mod 16PB
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.

MODERATOR.
Jun 19 '07 #4
imrosie
222 100+
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.
MODERATOR.
So sorry, I'll reply in proper format.
Rosie
Jun 19 '07 #5
ADezii
8,834 Expert 8TB
Hi ADezii,

Actually I'm trying to add a form to the image database, then have the switchboard open either documents or images. So I already had in there some of your declaration code:
Expand|Select|Wrap|Line Numbers
  1. 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
There is some 'Open Dialog' code there too (used for the images), sorry it's pretty long:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. ' Code to display standard "Open File" dialog.
  5.  
  6. Type OPENFILENAME
  7.   lStructSize As Long
  8.   hwndOwner As Long
  9.   hInstance As Long
  10.   lpstrFilter As String
  11.   lpstrCustomFilter As String
  12.   nMaxCustFilter As Long
  13.   nFilterIndex As Long
  14.   lpstrFile As String
  15.   nMaxFile As Long
  16.   lpstrFileTitle As String
  17.   nMaxFileTitle As Long
  18.   lpstrInitialDir As String
  19.   lpstrTitle As String
  20.   flags As Long
  21.   nFileOffset As Integer
  22.   nFileExtension As Integer
  23.   lpstrDefExt As String
  24.   lCustData As Long
  25.   lpfnHook As Long
  26.   lpTemplateName As String
  27. End Type
  28.  
  29. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
  30.   "GetOpenFileNameA" (OFN As OPENFILENAME) As Boolean
  31.  
  32. Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
  33.   "GetSaveFileNameA" (OFN As OPENFILENAME) As Boolean
  34.  
  35. Private Const ALLFILES = "All files"
  36.  
  37. Function MakeFilterString(ParamArray varFilt() As Variant) As String
  38. ' Create filter string.
  39. ' Returns "" if there are no arguments.
  40. ' Expects an even number of arguments (filter name, extension).
  41. ' Adds *.* if the number of arguments is odd.
  42.  
  43.   Dim strFilter As String
  44.   Dim intRes As Integer
  45.   Dim intNum As Integer
  46.  
  47.   intNum = UBound(varFilt)
  48.   If (intNum <> -1) Then
  49.     For intRes = 0 To intNum
  50.       strFilter = strFilter & varFilt(intRes) & vbNullChar
  51.     Next
  52.     If intNum Mod 2 = 0 Then
  53.       strFilter = strFilter & "*.*" & vbNullChar
  54.     End If
  55.  
  56.     strFilter = strFilter & vbNullChar
  57.   End If
  58.  
  59.   MakeFilterString = strFilter
  60. End Function
  61.  
  62. Private Sub InitOFN(OFN As OPENFILENAME)
  63.   With OFN
  64.     ' Initialize fields user doesn't want to know about
  65.     .hwndOwner = hWndAccessApp
  66.     .hInstance = 0
  67.     .lpstrCustomFilter = vbNullString
  68.     .nMaxCustFilter = 0
  69.     .lpfnHook = 0
  70.     .lpTemplateName = 0
  71.     .lCustData = 0
  72.     .nMaxFile = 511
  73.     .lpstrFileTitle = String(512, vbNullChar)
  74.     .nMaxFileTitle = 511
  75.     .lStructSize = Len(OFN)
  76.     ' Use default filter if not specified.
  77.     If .lpstrFilter = "" Then
  78.       .lpstrFilter = MakeFilterString(ALLFILES)
  79.     End If
  80.     ' Pad lpstrFile with null chars.
  81.     .lpstrFile = .lpstrFile & String(512 - Len(.lpstrFile), vbNullChar)
  82.   End With
  83. End Sub
  84.  
  85. Function OpenDialog(OFN As OPENFILENAME) As Boolean
  86.   Dim intRes As Integer
  87.   InitOFN OFN
  88.   intRes = GetOpenFileName(OFN)
  89.   If intRes Then
  90.     ' Remove trailing null chars from lpstrFile.
  91.     With OFN
  92.       .lpstrFile = Left$(.lpstrFile, InStr(.lpstrFile, vbNullChar) - 1)
  93.     End With
  94.   End If
  95.   OpenDialog = intRes
  96. End Function

I was thinking I could add your code "Public Success As Boolean" to the Declaration module; add the function:
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
(as you suggested to Steve123) then I would have most of what I needed???


I'm not real clear on which mechanism to use for the viewing. for pdf's, Adobe, for .doc's, Word...etc. is that what you're referring to?
The problem is the graying out of the the cmdbutton you use.....until there's an absolute path. That's the part I'm trying to figure out. thanks

Rosie
I am attempting to build a form that allows for viewing files (txt, doc, rtf, xls, pdf) within a subform
.
Rosie, the previously illustrated technique will not allow you to do this. It will open a File within the Server Application that created it based on its Extension.
Jun 19 '07 #6
imrosie
222 100+
.

Rosie, the previously illustrated technique will not allow you to do this. It will open a File within the Server Application that created it based on its Extension.
Hi and thanks,

Is there anyway to alter your illustration in order to do that? I have a group of users that are utilizing the image database, where they can browse to a folder, select an image view it in the subform window, save if they choose, erase it. Now they're asking to do the same with documents..? The idea is to store up a repository of (full path links) so various groups can browse and find doc's quickly. The docs would be of various types (txt, xls, docs, pdfs...) That's why I thought your example would be perfect with some tweeking. thanks for your help.
Rosie
Jun 20 '07 #7
imrosie
222 100+
Hi ADezii,

Maybe I'm not explaining correctly. I want to open the files based on their extensions, exactly the same. I want to each user to be opened based on the applications their machines, such as if they have Adobe on their workstation, or Word..etc. I'm not expecting Access to open the files for editing.

Is this possible?
thanks
Rosie
Jun 20 '07 #8
missinglinq
3,532 Expert 2GB
So basically, you want to replace Windows Explorer with an Access database?
Jun 20 '07 #9
ADezii
8,834 Expert 8TB
Hi ADezii,

Maybe I'm not explaining correctly. I want to open the files based on their extensions, exactly the same. I want to each user to be opened based on the applications their machines, such as if they have Adobe on their workstation, or Word..etc. I'm not expecting Access to open the files for editing.

Is this possible?
thanks
Rosie
Yes it is. Each File will be opened on each Workstation (using ShellExecute()) based on the Default Application assigned to Open the specific File Extension as defined in the System Registry e.g. MS Paint may open a *.bmp on one PC, while that same File may be opened by another Graphic Application on another PC. Make sense?
Jun 20 '07 #10
NeoPa
32,556 Expert Mod 16PB
So basically, you want to replace Windows Explorer with an Access database?
Very similar Linq, but I suspect that the database will offer a certain level of restriction as to what can be accessed this way, as well as possibly a more 'simple' user interface for the operator.
Jun 20 '07 #11
imrosie
222 100+
So basically, you want to replace Windows Explorer with an Access database?
No that isn't my intent at all. I provided a user group with an image database, where they can browse to any folder containing images(bmps, jjpgs, tiffs, gifs), view an image within the (subform) window and the 'absolute' path to the image is stored (via 'add image' cmd). There also a control box on form to 'add' a new description. All this and the path to the actual file is stored in an image table.

Now my mgr (who used to be a programmer) has asked me to add the same capability to same database for documents (of any type). I'm a newbie, so I just assumed that it wouldn't be that hard but since I'm getting so many concerns about this it must be impossible.

My intent was to similarly establish a 'browse' to any folder containing documents and open/save. I searched around and found that it can be done using Windows File Open/Save dialog box (Ken Gertz). However, it will allow browse (outside of Access),save a filepath into a table and that's it.

From your response I''m gathering it is technically impossible to open/save path, and ALSO somehow view (like the images)
in an Access window?!? The purpose for the request is that several groups want to share documents amongst the group, store them in their group folders and in that 'Vewiing' window (if it were possible) edit a doc, and resave it back into the groups folder....

If I can get anything close to doing this it would be helpful. Or if I am totally in left field with this request...I'll let it go and move on. thanks

Rosie
Jun 20 '07 #12
imrosie
222 100+
Yes it is. Each File will be opened on each Workstation (using ShellExecute()) based on the Default Application assigned to Open the specific File Extension as defined in the System Registry e.g. MS Paint may open a *.bmp on one PC, while that same File may be opened by another Graphic Application on another PC. Make sense?
Hi ADezii,

Yes it does make sense. So how can I alter your code to get the results I want? thanks

Rosie
Jun 20 '07 #13
ADezii
8,834 Expert 8TB
Hi ADezii,

Yes it does make sense. So how can I alter your code to get the results I want? thanks

Rosie
From your response I''m gathering it is technically impossible to open/save path, and ALSO somehow view (like the images) in an Access window?
  1. Use a File Browsing utility to first locate the File.
  2. Retrieve the File and Save its Path to the underlying RecordSource for the Form.
  3. In order to Open the file within an 'Access Window', you would probably have to dynamically load it into an Unbound Object Frame on a Form.
  4. I'm assuming that this operation would have to be repeated frequently, why the need to store the Path if the File will loaded this way each time?
Jun 20 '07 #14
imrosie
222 100+
  1. Use a File Browsing utility to first locate the File.
  2. Retrieve the File and Save its Path to the underlying RecordSource for the Form.
  3. In order to Open the file within an 'Access Window', you would probably have to dynamically load it into an Unbound Object Frame on a Form.
  4. I'm assuming that this operation would have to be repeated frequently, why the need to store the Path if the File will loaded this way each time?
Hi ADezii,
"why the need to store the Path if the File will loaded this way each time?"

Because the 'File and Save its Path to the underlying RecordSource' for the Form I believe is the path only to the original file. These documents will be altered by group members and somehow stored with a new description (added to identify it) by a different table field hopefully.
Also there is another combo control on the Form which holds a list of the 'stored' altered docs which points to the new stored location. So a person can (double-click to) select a doc from the combo control by its' description.

Yes, you're right, this operation would be repeated frequently. I have 3 departments waiting with baited breath for something like this to work....again, I'm newbie who has limited knowledge. I'm going off now to research how to implement your suggestion of "Open the file within an 'Access Window', you would probably have to dynamically load it into an Unbound Object Frame on a Form"

Thanks and any help you can provide would be greatly appreciated.

Rosie
Jun 20 '07 #15
ADezii
8,834 Expert 8TB
Hi ADezii,
"why the need to store the Path if the File will loaded this way each time?"

Because the 'File and Save its Path to the underlying RecordSource' for the Form I believe is the path only to the original file. These documents will be altered by group members and somehow stored with a new description (added to identify it) by a different table field hopefully.
Also there is another combo control on the Form which holds a list of the 'stored' altered docs which points to the new stored location. So a person can (double-click to) select a doc from the combo control by its' description.

Yes, you're right, this operation would be repeated frequently. I have 3 departments waiting with baited breath for something like this to work....again, I'm newbie who has limited knowledge. I'm going off now to research how to implement your suggestion of "Open the file within an 'Access Window', you would probably have to dynamically load it into an Unbound Object Frame on a Form"

Thanks and any help you can provide would be greatly appreciated.

Rosie
This should point you in the right direction:
The following example creates a linked OLE object using an Unbound Object Frame named OLE1 and sizes the control to display the object's entire contents when the user clicks a command button.

Expand|Select|Wrap|Line Numbers
  1. Dim strFileName As String          
  2. strFileName = "C:\Test\Test.xls"        'retrieved by any means necessary
  3.  
  4. OLE1.Class = "Excel.Sheet"    ' Set class name.
  5.  
  6. ' Specify type of object.
  7. OLE1.OLETypeAllowed = acOLELinked
  8.  
  9. ' Specify source file.
  10. OLE1.SourceDoc = strFileName
  11.  
  12. ' Create linked object.
  13. OLE1.Action = acOLECreateLink
  14.  
  15. ' Adjust control size.
  16. OLE1.SizeMode = acOLESizeZoom
A couple of other things I forgot to mention:
  1. Set the Enabled Property of the Unbound OLE Object Frame = Yes.
  2. Set the Locked Property of the Unbound Object Frame = No.
  3. Experiment with the SizeMode Property (Reference the Help Files).
Jun 21 '07 #16
imrosie
222 100+
This should point you in the right direction:
The following example creates a linked OLE object using an Unbound Object Frame named OLE1 and sizes the control to display the object's entire contents when the user clicks a command button.

Expand|Select|Wrap|Line Numbers
  1. Dim strFileName As String          
  2. strFileName = "C:\Test\Test.xls"        'retrieved by any means necessary
  3.  
  4. OLE1.Class = "Excel.Sheet"    ' Set class name.
  5.  
  6. ' Specify type of object.
  7. OLE1.OLETypeAllowed = acOLELinked
  8.  
  9. ' Specify source file.
  10. OLE1.SourceDoc = strFileName
  11.  
  12. ' Create linked object.
  13. OLE1.Action = acOLECreateLink
  14.  
  15. ' Adjust control size.
  16. OLE1.SizeMode = acOLESizeZoom
A couple of other things I forgot to mention:
  1. Set the Enabled Property of the Unbound OLE Object Frame = Yes.
  2. Set the Locked Property of the Unbound Object Frame = No.
  3. Experiment with the SizeMode Property (Reference the Help Files).
thanks ADezii,

I've been playing with unbound Object Frame most of the day....as yet it wasn't doing what I wanted...I going to implement this now..

Am I correct in assuming this code goes behind a (one) control on my form (or inside of the subform on the form)??

thanks
Rosie
Jun 21 '07 #17

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

Similar topics

3
by: Ted Byers | last post by:
This is quite frustrating! In the documents, and in the newsgroups, I see simple instructions like the following: =============================================== ==========Beginning of Ray's...
1
by: JoeBobHankey | last post by:
Background: - I'm running MSDE 2000 (not client tools, stored procedure capability, etc). This may change, but not in the first part of development. - My Access file is an Access 2002 project...
6
by: JimmyKoolPantz | last post by:
I have been given the task of converting a program from VFP (visual foxpro) to Visual Basic.net. My question is "Is it possible to generate a DBF file Dynamically(at runtime) using Visual...
5
by: sphinney | last post by:
Basic question: Does anyone know how to go about adding a control to an Access 2007 form that will allow viewing a Word 2007 document? Reason for asking: My office is about to receive 100+/-...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.