Connecting Tech Pros Worldwide Help | Site Map

Need "Browse for File" button

 
LinkBack Thread Tools Search this Thread
 
Old February 13th, 2008, 03:46 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default Need "Browse for File" button

I need some help. I need a button on an Access form that allows the user to browse for a file on our network, and insert it in a field (rather than having to type a path). I dont need any filters because the files can be any number of formats.

I've come across a couple of so-called "simple" solutions, but for the life of me, I either cant understand them or I cant get them to work. I know nothing about VB so if someone can provide a truly simple answer (preferably something I could cut and paste) with clear instructions on how to actually get it to work, I'd be VERY grateful.

Oh, I am coding this in Access 2000, but if I need to, I can code it in Access 2002-2003.

Thanks!
Barb
Reply
  #51  
Old March 11th, 2008, 01:59 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

That's awesome!

Where do I put the code? And what do I do with the code you previously gave me? Does one replace the other?

Thanks!

Quote:
Originally Posted by ADezii
Here is a code segment which will:
  1. Allow you to select Multiple Files.
  2. Check every Selected File, and if it is one of the specified Formats, dynamically loads its Path into an Array.
  3. The prior contents of the Array are Preserved and it is Re-dimensioned.
  4. All the Selected File Paths are now contained in the Array arrsGraphicFiles().
  5. List all these Files and their Paths to the Immediate Window.
  6. To test the code, I selected hundreds of Files in the Windows Directory, 6 of which were of a Graphic nature (*.bmp).
  7. The results are listed below, as well as the code.
Expand|Select|Wrap|Line Numbers
  1. Dim fdg As FileDialog, vrtSelectedItem As Variant
  2. Dim strSelectedFile As String, strImagePath As String
  3. Dim intCounter As Integer, arrsGraphicFiles() As String
  4.  
  5. Set fdg = Application.FileDialog(msoFileDialogFilePicker)
  6.  
  7. intCounter = 0
  8.  
  9. With fdg
  10. .AllowMultiSelect = True
  11. .InitialView = msoFileDialogViewDetails
  12. If .Show = -1 Then
  13. For Each vrtSelectedItem In .SelectedItems
  14. Select Case Right$(vrtSelectedItem, 4)
  15. Case ".wmf", ".emf", ".dib", ".bmp", ".ico", ".gif", ".jpg"
  16. intCounter = intCounter + 1
  17. ReDim Preserve arrsGraphicFiles(intCounter) 'Redimension and Preserve
  18. arrsGraphicFiles(intCounter) = vrtSelectedItem
  19. Case Else
  20. End Select
  21. Next vrtSelectedItem
  22. Else 'The user pressed Cancel.
  23. End If
  24. End With
  25.  
  26. Set fdg = Nothing
  27.  
  28. 'Display the Selected/Graphic Files
  29. For intCounter = 1 To UBound(arrsGraphicFiles)
  30. Debug.Print arrsGraphicFiles(intCounter)
  31. Next
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. C:\WINDOWS\Prairie Wind.bmp
  2. C:\WINDOWS\Rhododendron.bmp
  3. C:\WINDOWS\River Sumida.bmp
  4. C:\WINDOWS\Santa Fe Stucco.bmp
  5. C:\WINDOWS\Soap Bubbles.bmp
  6. C:\WINDOWS\Zapotec.bmp
Reply
  #52  
Old March 11th, 2008, 02:43 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
That's awesome!

Where do I put the code? And what do I do with the code you previously gave me? Does one replace the other?

Thanks!
Here is the way I would handle the situation. Assuming you wish to maintain multiple, linked, Hyperlink Attachments for a single Record, I would create a Child Table that contains the Linked Graphic Files in a Hyperlink Field and has a MANY to 1 Relationship with the Parent Table based on a Child Key in the Attachment Table and a Primary Key in the Parent Table. All the hyperlinked Attachments can now be displayed in a Sub-Form on the Main Form and activated when necessary. Be advised that any modification to these File Paths will cause many problems since they are Linked. If you wish to proceed along these lines, let me know and we'll take it step by step. If you are in a rush, in all honesty, we'll have to drop the idea because this solution is not that simple. I won't do anything until I hear from you.
Reply
  #53  
Old March 11th, 2008, 06:27 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

No, I'm not in a rush. The only thing that had a rush on it was getting the basic functions up and running (MUCH thanks for helping to make that happen). Now I'm getting all kinds of requests to add features. I'm trying to address them according to their proper priority and doability given my programming limitations. (I'm trying to get approval to take an Access IV class that covers VBA)

Anyway, this one is at the top of the list of things that are known to be doable. It is something that will be extremely helpful, and necessary for the big picture, but it's not time sensative. It's more important to get it working properly before I add the function to the application.

So where do I start? I think I have the tables already set up (though I might need to add fields). I was going to attach a snapshot of the relationships so you could confirm that it's done properly, but I dont see any options in the window that allow me to do so. Should I email it to you?

Thanks!

Quote:
Originally Posted by ADezii
Here is the way I would handle the situation. Assuming you wish to maintain multiple, linked, Hyperlink Attachments for a single Record, I would create a Child Table that contains the Linked Graphic Files in a Hyperlink Field and has a MANY to 1 Relationship with the Parent Table based on a Child Key in the Attachment Table and a Primary Key in the Parent Table. All the hyperlinked Attachments can now be displayed in a Sub-Form on the Main Form and activated when necessary. Be advised that any modification to these File Paths will cause many problems since they are Linked. If you wish to proceed along these lines, let me know and we'll take it step by step. If you are in a rush, in all honesty, we'll have to drop the idea because this solution is not that simple. I won't do anything until I hear from you.
Reply
  #54  
Old March 11th, 2008, 11:33 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
No, I'm not in a rush. The only thing that had a rush on it was getting the basic functions up and running (MUCH thanks for helping to make that happen). Now I'm getting all kinds of requests to add features. I'm trying to address them according to their proper priority and doability given my programming limitations. (I'm trying to get approval to take an Access IV class that covers VBA)

Anyway, this one is at the top of the list of things that are known to be doable. It is something that will be extremely helpful, and necessary for the big picture, but it's not time sensative. It's more important to get it working properly before I add the function to the application.

So where do I start? I think I have the tables already set up (though I might need to add fields). I was going to attach a snapshot of the relationships so you could confirm that it's done properly, but I dont see any options in the window that allow me to do so. Should I email it to you?

Thanks!
  1. What is the name of your Primary/Main Table, the Table for which the Attachment Table, will be a Child to?
    Expand|Select|Wrap|Line Numbers
    1. ([Primary Table].[Primary Key]{1} ==> [Child Table].[Foreign Key[{MANY})
  2. What is the Primary Key Field of the Main Table?
  3. What is the Data Type of the Primary Key Field?
  4. List the Fields and their Data types in thia Main Table.
  5. Does your Main Form have the Main Table as its Record Source?
  6. What is the name of your Main Form?
  7. For now, create the Child Table and Name it tblAttachments. It should consist of the following Fields:
    1. [AttachID] - (AutoNumber) - {Primary Key}
    2. [ID] - (Data Type to be determined since it depends on the Data Type of the Primary Key Field in the Main Table. This will be the Foreign Key Field relating back to the Primary Key Field in the Main Table).
    3. [File] - (HyperLink) - [enables Link to selected File(s)].
Reply
  #55  
Old March 12th, 2008, 04:23 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

1. The Primary Table is tbl_SurveyWorkOrder
2. The Primary Key for tbl_SurveyWorkOrder is SurveyWorkOrderID
3. The Data Type for the Primary Key Field is AutoNumber
4. Fields & Data Types in Main Table (tbl_SurveyWorkOrder):
SurveyWorkOrderID – Long Integer
DateCreated – Date/Time Priority – Text
QAQC – Yes/No
OfficeComplete – Yes/No
FieldComplete – Yes/No
NotifiedOwner – Yes/No
RequestedBy – Text
ProjectID – Text
Phases – Text
ProjectEngineer – Text
ProjectSurveyor – Text
CADTech – Text
SurveyPurpose – Text
ProjectLimits – Text
Description – Memo
KOMeetingDate – Date/Time
KOMeetingTime – Text
KOMeetingLoc – Text
DatumHorizontal – Long Integer
DatumVertical – Long Integer
Alignments – Yes/No
ControlNetwork – Yes/No
RealPropertyResearch – Yes/No
ExistingRW – Yes/No
SurveyOfRecordResearch – Yes/No
ExistingMonumentation/Boundary – Yes/No
TitleRecieved – Yes/No
Control_Other – Text
Suplemental – Yes/No
AppraisalStaking – Yes/No
PropertyMonumentation – Yes/No
DTM – Yes/No
WetlandLocations – Yes/No
UtilityCoordination – Yes/No
BoringLocations – Yes/No
CrossSections – Yes/No
SlopeStaking – Yes/No
CollectSystemMaps – Yes/No
AsBuilts – Yes/No
ExistingMonumentation – Yes/No
Design_Other – Text
StakeabilityCheck – Text
ErosionControlStaking – Yes/No
BlueTops – Yes/No
GradeStaking – Yes/No
RedTops – Yes/No
SanitarySewerStaking – Yes/No
StormSewerStaking – Yes/No
WaterMainStaking – Yes/No
CurbGutter – Yes/No
ConstStaking_Other – Text
5. Main Form has a query qry_SurveyWorkOrderForm as its Record Source

6. The Main Form is frm_CreateSurveyWorkOrder

7. I already have a child table tbl_Images with the following fields:

[ImageID] (Auto Number / Primary Key) – Long Integer [SurveyWorkOrderID] (Primary key in Main Table) – Long Integer
[Link] – Hyperlink

This table is currently being used by the original application you helped me with. Is it ok to use this table, or do you need me to create a new one? If this one is ok, do you need me to rename any of the fields

Thanks!



Quote:
Originally Posted by ADezii
  1. What is the name of your Primary/Main Table, the Table for which the Attachment Table, will be a Child to?
    Expand|Select|Wrap|Line Numbers
    1. ([Primary Table].[Primary Key]{1} ==> [Child Table].[Foreign Key[{MANY})
  2. What is the Primary Key Field of the Main Table?
  3. What is the Data Type of the Primary Key Field?
  4. List the Fields and their Data types in thia Main Table.
  5. Does your Main Form have the Main Table as its Record Source?
  6. What is the name of your Main Form?
  7. For now, create the Child Table and Name it tblAttachments. It should consist of the following Fields:
    1. [AttachID] - (AutoNumber) - {Primary Key}
    2. [ID] - (Data Type to be determined since it depends on the Data Type of the Primary Key Field in the Main Table. This will be the Foreign Key Field relating back to the Primary Key Field in the Main Table).
    3. [File] - (HyperLink) - [enables Link to selected File(s)].
Reply
  #56  
Old March 12th, 2008, 08:19 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
1. The Primary Table is tbl_SurveyWorkOrder
2. The Primary Key for tbl_SurveyWorkOrder is SurveyWorkOrderID
3. The Data Type for the Primary Key Field is AutoNumber
4. Fields & Data Types in Main Table (tbl_SurveyWorkOrder):
SurveyWorkOrderID – Long Integer
DateCreated – Date/Time Priority – Text
QAQC – Yes/No
OfficeComplete – Yes/No
FieldComplete – Yes/No
NotifiedOwner – Yes/No
RequestedBy – Text
ProjectID – Text
Phases – Text
ProjectEngineer – Text
ProjectSurveyor – Text
CADTech – Text
SurveyPurpose – Text
ProjectLimits – Text
Description – Memo
KOMeetingDate – Date/Time
KOMeetingTime – Text
KOMeetingLoc – Text
DatumHorizontal – Long Integer
DatumVertical – Long Integer
Alignments – Yes/No
ControlNetwork – Yes/No
RealPropertyResearch – Yes/No
ExistingRW – Yes/No
SurveyOfRecordResearch – Yes/No
ExistingMonumentation/Boundary – Yes/No
TitleRecieved – Yes/No
Control_Other – Text
Suplemental – Yes/No
AppraisalStaking – Yes/No
PropertyMonumentation – Yes/No
DTM – Yes/No
WetlandLocations – Yes/No
UtilityCoordination – Yes/No
BoringLocations – Yes/No
CrossSections – Yes/No
SlopeStaking – Yes/No
CollectSystemMaps – Yes/No
AsBuilts – Yes/No
ExistingMonumentation – Yes/No
Design_Other – Text
StakeabilityCheck – Text
ErosionControlStaking – Yes/No
BlueTops – Yes/No
GradeStaking – Yes/No
RedTops – Yes/No
SanitarySewerStaking – Yes/No
StormSewerStaking – Yes/No
WaterMainStaking – Yes/No
CurbGutter – Yes/No
ConstStaking_Other – Text
5. Main Form has a query qry_SurveyWorkOrderForm as its Record Source

6. The Main Form is frm_CreateSurveyWorkOrder

7. I already have a child table tbl_Images with the following fields:

[ImageID] (Auto Number / Primary Key) – Long Integer [SurveyWorkOrderID] (Primary key in Main Table) – Long Integer
[Link] – Hyperlink

This table is currently being used by the original application you helped me with. Is it ok to use this table, or do you need me to create a new one? If this one is ok, do you need me to rename any of the fields

Thanks!
Give me a little time to digest everything, so I can figure out the best approach.
Reply
  #57  
Old March 12th, 2008, 08:54 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

Absolutely.

Thanks!

Quote:
Originally Posted by ADezii
Give me a little time to digest everything, so I can figure out the best approach.
Reply
  #58  
Old March 14th, 2008, 11:53 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Rather that going into a detailed, extended description of how to implement multiple, linked Attachments, I'll post the critical code below and also make the Test Database which I used for testing with this Thread available to you as a Attachment. Simply Open the database, add data to the Parent Form, click on the Browse Files button, select as many 'Attachments' as you like, then OK. The selected Files will be filtered for Graphic Files only, dynamically added to the Child Table (tblImages) as Hyperlinks, the Image Sub-Form (subfImages) will then be Re-queried, and the Attachments will be displayed within the Sub-Form. You now can click on any Attachment in the Sub-Form to open it. I have provided you with everything you need to accomplish the task at hand, it is now up to you to make any necessary changes, and incorporate everything into your existing structure. Virtually all of your naming conventions have been maintained, so that this transition will be as painless as possible.

Note: Important points to remember:
  1. You must Save a Record to the Parent Table (tbl_SurveyWorkOrder) before you can Save any Attachments to the Child Table (tblImages). This applies to New Records, naturally. The code partially looks for this by checking the NewRecord Property of the Parent Form (frmCreateSurveyWorkOrder), if it is true the code will then attempt to Save the Record before adding any Attachments.
  2. It is up to you to see that all Required Fields are filled in and all Validation Rules are met before adding any Attachments. This can be accomplished by either the use of Data Validation and/or Error Trapping.
  3. Do not remove the simple Error Trap in the code, it is critical it that it prevents the populating of the Sub-Form in the event of an Error triggered by a Main Form Save.
  4. Referential Integrity (RI) with Cascading Updates and Deletes is enforced between the Parent and Child Tables. Should you Delete a Record in the Main Form ALL Attachments for that Record will be deleted also.
  5. Remember, this entire system relies heavily on Hyperlinks, so do not Delete, Rename, or Move these Files or else the walls come tumbling down when you tray to activate them.
  6. The code has been thoroughly tested and actually works quite well, can you believe that?
  7. Whew! That's All Folks! - any questions feel free to ask.
  8. Good Luck and Good Night!
Expand|Select|Wrap|Line Numbers
  1. Private Sub AddGraphicLinks(strFileName As String, lngID As Long)
  2. Dim MyDB As Database
  3. Dim MyRS As Recordset
  4.  
  5. Set MyDB = CurrentDb
  6. Set MyRS = MyDB.OpenRecordset("tblImages", dbOpenDynaset)
  7.  
  8. With MyRS
  9.   .AddNew
  10.     ![SurveyWorkOrderID] = lngID
  11.     ![Link] = strFileName & "#" & strFileName
  12.   .Update
  13. End With
  14.  
  15. MyRS.Close
  16. Set MyRS = Nothing
  17. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2. On Error GoTo Err_Command0_Click
  3.  
  4. Dim fdg As FileDialog
  5. Dim vrtSelectedItem As Variant
  6. Dim strSelectedFile As String
  7. Dim strImagePath As String
  8. Dim intCounter As Integer
  9. Dim arrsGraphicFiles() As String
  10.  
  11. Set fdg = Application.FileDialog(msoFileDialogFilePicker)
  12.  
  13. intCounter = 0      'Initialize Counter
  14.  
  15. With fdg
  16.   .AllowMultiSelect = True
  17.   .InitialView = msoFileDialogViewDetails
  18.     If .Show = -1 Then
  19.      'If this is a New Record, then we must force a Save Record before attempting
  20.      'to add Records to the Images Table. If a problem occurs, such as a Required Field
  21.      'is missing, the Error Trap will pick it up then Exit the Sub-Routine
  22.         For Each vrtSelectedItem In .SelectedItems
  23.           Select Case Right$(vrtSelectedItem, 4)
  24.             Case ".wmf", ".emf", ".dib", ".bmp", ".ico", ".gif", ".jpg"
  25.             If Me.NewRecord Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  26.               intCounter = intCounter + 1
  27.               ReDim Preserve arrsGraphicFiles(intCounter)     'Redimension and Preserve
  28.               arrsGraphicFiles(intCounter) = vrtSelectedItem
  29.             Case Else
  30.           End Select
  31.         Next vrtSelectedItem
  32.     Else        'The user pressed Cancel.
  33.       Exit Sub
  34.     End If
  35. End With
  36.  
  37. Set fdg = Nothing
  38.  
  39. If intCounter > 0 Then      'at least 1 Graphic File was selected
  40.   'Display the Selected/Graphic Files
  41.   For intCounter = 1 To UBound(arrsGraphicFiles)
  42.     Call AddGraphicLinks(arrsGraphicFiles(intCounter), Me![SurveyWorkOrderID])
  43.     Debug.Print arrsGraphicFiles(intCounter)
  44.   Next
  45.   Forms!frm_CreateSurveyWorkOrder!subfImages.Form.Requery
  46. Else
  47.   MsgBox "No Graphic Files (.wmf, .emf, .dib, .bmp, .ico, .gif, .jpg) were selected", vbExclamation, "No Files Selected"
  48. End If
  49.  
  50. Exit_Command0_Click:
  51.   Exit Sub
  52.  
  53. Err_Command0_Click:
  54.   MsgBox Err.Description, vbExclamation, "Error in Command0_Click()"
  55.   Resume Exit_Command0_Click
  56. End Sub
Reply
  #59  
Old March 17th, 2008, 01:08 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

Whew is right!

I'll start work on it this morning and let you know how it goes.

Thanks soooo much!

Quote:
Originally Posted by ADezii
Rather that going into a detailed, extended description of how to implement multiple, linked Attachments, I'll post the critical code below and also make the Test Database which I used for testing with this Thread available to you as a Attachment. Simply Open the database, add data to the Parent Form, click on the Browse Files button, select as many 'Attachments' as you like, then OK. The selected Files will be filtered for Graphic Files only, dynamically added to the Child Table (tblImages) as Hyperlinks, the Image Sub-Form (subfImages) will then be Re-queried, and the Attachments will be displayed within the Sub-Form. You now can click on any Attachment in the Sub-Form to open it. I have provided you with everything you need to accomplish the task at hand, it is now up to you to make any necessary changes, and incorporate everything into your existing structure. Virtually all of your naming conventions have been maintained, so that this transition will be as painless as possible.

Note: Important points to remember:[list=1][*]You must Save a Record to the Parent Table (tbl_SurveyWorkOrder) before you can Save any Attachments to the Child Table (tblImages). This applies to New Records, naturally. The code partially looks for this by checking the NewRecord Property of the Parent Form (frmCreateSurveyWorkOrder), if it is true the code will then attempt to Save the Record before adding any Attachments.[*]It is up to you to see that all Required Fields are filled in and all Validation Rules are met before adding any Attachments. This can be accomplished by either the use of Data Validation and/or Error Trapping.[*]Do not remove the simple Error Trap in the code, it is critical it that it prevents the populating of the Sub-Form in the event of an Error triggered by a Main Form Save.[*]Referential Integrity (RI) with Cascading Updates and Deletes is enforced between the Parent and Child Tables. Should you Delete a Record in the Main Form ALL Attachments for that Record will be deleted also.[*]Remember, this entire system relies heavily on Hyperlinks, so do not Delete, Rename, or Move these Files or else the walls come tumbling down when you tray to activate them.[*]The code has been thoroughly tested and actually works quite well, can you believe that?[*]Whew! That's All Folks! - any questions feel free to ask.[*]Good Luck and Good Night!
...

Last edited by Scott Price; March 17th, 2008 at 01:53 PM. Reason: shortened quoted code so the reply will show
Reply
  #60  
Old March 17th, 2008, 04:05 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
Whew is right!

I'll start work on it this morning and let you know how it goes.

Thanks soooo much!
You are quite welcome, keep in touch.
Reply
  #61  
Old March 26th, 2008, 09:26 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

I'm back! I hope you had a nice Easter weekend.

Thank you so much for all your hard work on this. I'd have had it done sooner, but things were busy and today was the first day I had enough time to work on it.

Ok, this is where I am. I've got the multiple file select working. I wasnt able to get it to work inside the existing forms, but that's ok. I just created a button to launch the form (I made a few minor modifications) and it works wonderfully. In fact, I prefer it open the window since the form is already so busy.

One thing I would like, though, is not to limit the files selected to just the image files you have listed. Is there a way of removing the file restrictions, or is it better to just add the different file formats that might be chosen?

The other thing is I'm having trouble with is the reports. I would like a text list of the selected files to display, so I tried using a subreport, but even though I had it set up to syncrhonize the report with the work order number, when I try to preview the report, it asks me for the work order number.

Also, if there are multiple graphic image, the work order will print out as many copies as there are graphic images with one image per page. Is there any way of getting them all to print as one report?

Thanks!




Quote:
Originally Posted by ADezii
You are quite welcome, keep in touch.
Reply
  #62  
Old March 26th, 2008, 11:11 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
I'm back! I hope you had a nice Easter weekend.

Thank you so much for all your hard work on this. I'd have had it done sooner, but things were busy and today was the first day I had enough time to work on it.

Ok, this is where I am. I've got the multiple file select working. I wasnt able to get it to work inside the existing forms, but that's ok. I just created a button to launch the form (I made a few minor modifications) and it works wonderfully. In fact, I prefer it open the window since the form is already so busy.

One thing I would like, though, is not to limit the files selected to just the image files you have listed. Is there a way of removing the file restrictions, or is it better to just add the different file formats that might be chosen?

The other thing is I'm having trouble with is the reports. I would like a text list of the selected files to display, so I tried using a subreport, but even though I had it set up to syncrhonize the report with the work order number, when I try to preview the report, it asks me for the work order number.

Also, if there are multiple graphic image, the work order will print out as many copies as there are graphic images with one image per page. Is there any way of getting them all to print as one report?

Thanks!
Quote:
One thing I would like, though, is not to limit the files selected to just the image files you have listed. Is there a way of removing the file restrictions, or is it better to just add the different file formats that might be chosen?
One step at a time, to remove the Graphic File restrictions, (it's not a Filter), replace your code block with the one below:
Expand|Select|Wrap|Line Numbers
  1. Dim fdg As FileDialog
  2. Dim vrtSelectedItem As Variant
  3. Dim strSelectedFile As String
  4. Dim strImagePath As String
  5. Dim intCounter As Integer
  6. Dim arrsGraphicFiles() As String
  7.  
  8. Set fdg = Application.FileDialog(msoFileDialogFilePicker)
  9.  
  10. intCounter = 0      'Initialize Counter
  11.  
  12. With fdg
  13.   .AllowMultiSelect = True
  14.   .InitialView = msoFileDialogViewDetails
  15.     If .Show = -1 Then
  16.      'If this is a New Record, then we must force a Save Record before attempting
  17.      'to add Records to the Images Table. If a problem occurs, such as a Required Field
  18.      'is missing, the Error Trap will pick it up then Exit the Sub-Routine
  19.         For Each vrtSelectedItem In .SelectedItems
  20.           If Me.NewRecord Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  21.             intCounter = intCounter + 1
  22.             ReDim Preserve arrsGraphicFiles(intCounter)     'Redimension and Preserve
  23.             arrsGraphicFiles(intCounter) = vrtSelectedItem
  24.         Next vrtSelectedItem
  25.     Else        'The user pressed Cancel.
  26.       Exit Sub
  27.     End If
  28. End With
  29.  
  30. Set fdg = Nothing
  31.  
  32. If intCounter > 0 Then      'at least 1 Graphic File was selected
  33.   'Display the Selected Files
  34.   For intCounter = 1 To UBound(arrsGraphicFiles)
  35.     Call AddGraphicLinks(arrsGraphicFiles(intCounter), Me![SurveyWorkOrderID])
  36.     Debug.Print arrsGraphicFiles(intCounter)
  37.   Next
  38.   Forms!frm_CreateSurveyWorkOrder!subfImages.Form.Requery
  39. Else
  40.   MsgBox "No Files Selected were selected", vbExclamation, "No Files Selected"
  41. End If
Reply
  #63  
Old March 31st, 2008, 12:49 AM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

I got this error message:
Microsoft Office Access cant find the form 'frm_CreateSurveyWorkOrder' referred to in a macro expression or Visual Basic code.


It's probably because I dont have the function imedded in the forms. I have the forms launch a separate form frm_RelatedFiles. I tried replacing that file name with the one above, but got this error message:
Application-defined or object-defined error


Quote:
Originally Posted by ADezii
One step at a time, to remove the Graphic File restrictions, (it's not a Filter), replace your code block with the one below:
Expand|Select|Wrap|Line Numbers
  1. Dim fdg As FileDialog
  2. Dim vrtSelectedItem As Variant
  3. Dim strSelectedFile As String
  4. Dim strImagePath As String
  5. Dim intCounter As Integer
  6. Dim arrsGraphicFiles() As String
  7.  
  8. Set fdg = Application.FileDialog(msoFileDialogFilePicker)
  9.  
  10. intCounter = 0 'Initialize Counter
  11.  
  12. With fdg
  13. .AllowMultiSelect = True
  14. .InitialView = msoFileDialogViewDetails
  15. If .Show = -1 Then
  16. 'If this is a New Record, then we must force a Save Record before attempting
  17. 'to add Records to the Images Table. If a problem occurs, such as a Required Field
  18. 'is missing, the Error Trap will pick it up then Exit the Sub-Routine
  19. For Each vrtSelectedItem In .SelectedItems
  20. If Me.NewRecord Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  21. intCounter = intCounter + 1
  22. ReDim Preserve arrsGraphicFiles(intCounter) 'Redimension and Preserve
  23. arrsGraphicFiles(intCounter) = vrtSelectedItem
  24. Next vrtSelectedItem
  25. Else 'The user pressed Cancel.
  26. Exit Sub
  27. End If
  28. End With
  29.  
  30. Set fdg = Nothing
  31.  
  32. If intCounter > 0 Then 'at least 1 Graphic File was selected
  33. 'Display the Selected Files
  34. For intCounter = 1 To UBound(arrsGraphicFiles)
  35. Call AddGraphicLinks(arrsGraphicFiles(intCounter), Me![SurveyWorkOrderID])
  36. Debug.Print arrsGraphicFiles(intCounter)
  37. Next
  38. Forms!frm_CreateSurveyWorkOrder!subfImages.Form.Requery
  39. Else
  40. MsgBox "No Files Selected were selected", vbExclamation, "No Files Selected"
  41. End If
Reply
  #64  
Old March 31st, 2008, 01:51 AM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
I got this error message:
Microsoft Office Access cant find the form 'frm_CreateSurveyWorkOrder' referred to in a macro expression or Visual Basic code.


It's probably because I dont have the function imedded in the forms. I have the forms launch a separate form frm_RelatedFiles. I tried replacing that file name with the one above, but got this error message:
Application-defined or object-defined error


  1. Where exactly is this Error occurring?
  2. Try using an absolute reference:
    Expand|Select|Wrap|Line Numbers
    1. Forms!frm_CreateSurveyWorkOrder
Reply
  #65  
Old March 31st, 2008, 01:46 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

I'm not sure what you mean by where it's occuring. I replaced the current code with the code you supplied and that's the error message I got.

As for using an absolute reference, where would I put that?

Also, the name of the form is now frm_RelatedFiles because the function is accessed by several forms, so it was easier to just supply a button to pull up this new form.

I did try replacing the previous form name with the new form name, but that's when I got the error message "Application-defined or object-defined error"
Quote:
Originally Posted by ADezii
  1. Where exactly is this Error occurring?
  2. Try using an absolute reference:
    Expand|Select|Wrap|Line Numbers
    1. Forms!frm_CreateSurveyWorkOrder
Reply
  #66  
Old March 31st, 2008, 07:12 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
I'm not sure what you mean by where it's occuring. I replaced the current code with the code you supplied and that's the error message I got.

As for using an absolute reference, where would I put that?

Also, the name of the form is now frm_RelatedFiles because the function is accessed by several forms, so it was easier to just supply a button to pull up this new form.

I did try replacing the previous form name with the new form name, but that's when I got the error message "Application-defined or object-defined error"
Can you send me the Database as a Zip file?
Reply
  #67  
Old March 31st, 2008, 08:01 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

I just sent it. Thanks!!

Quote:
Originally Posted by ADezii
Can you send me the Database as a Zip file?
Reply
  #68  
Old March 31st, 2008, 11:45 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
I just sent it. Thanks!!
Truthlover, I am totally confused. I assumed that this code was to be contained in the Click() Event of the 'Click to Add Related Images and/or Files' Command Button on frm_CreateSurveyWorkOrder, but you have the following pre-existing code there instead, please explain:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2. Dim stLinkCriteria As String
  3.  
  4. stDocName = "frm_RelatedFiles"
  5.  
  6. stLinkCriteria = "[tbl_SurveyWorkOrder.SurveyWorkOrderID]=" & Me![tbl_SurveyWorkOrder.SurveyWorkOrderID]
  7. DoCmd.OpenForm stDocName, , , stLinkCriteria
  1. I need to know:
    1. Exactly where, on frm_CreateSurveyWorkOrder, does this code get placed.
    2. The way it is now structured this code exists in limbo, and is not associated with any specific Object.
Reply
  #69  
Old April 1st, 2008, 01:35 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

Quote:
Originally Posted by ADezii
Truthlover, I am totally confused. I assumed that this code was to be contained in the Click() Event of the 'Click to Add Related Images and/or Files' Command Button on frm_CreateSurveyWorkOrder
No, the buttons on the main forms simply bring up the frm_RelatedFiles form which contains the code that makes the application run. (I had to do that because there are at least two forms that use that application)
Quote:
you have the following pre-existing code there instead, please explain:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2. Dim stLinkCriteria As String
  3.  
  4. stDocName = "frm_RelatedFiles"
  5.  
  6. stLinkCriteria = "[tbl_SurveyWorkOrder.SurveyWorkOrderID]=" & Me![tbl_SurveyWorkOrder.SurveyWorkOrderID]
  7. DoCmd.OpenForm stDocName, , , stLinkCriteria
That is the code that Access generated when I created the button to launch the frm_RelatedFiles form that contains the application to add the different files.
Quote:
The way it is now structured this code exists in limbo, and is not associated with any specific Object.
The code should be in the frm_RelatedFiles form. It seems to be working properly. Did i do something wrong?

Quote:
Originally Posted by ADezii
Truthlover, I am totally confused. I assumed that this code was to be contained in the Click() Event of the 'Click to Add Related Images and/or Files' Command Button on frm_CreateSurveyWorkOrder, but you have the following pre-existing code there instead, please explain:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2. Dim stLinkCriteria As String
  3.  
  4. stDocName = "frm_RelatedFiles"
  5.  
  6. stLinkCriteria = "[tbl_SurveyWorkOrder.SurveyWorkOrderID]=" & Me![tbl_SurveyWorkOrder.SurveyWorkOrderID]
  7. DoCmd.OpenForm stDocName, , , stLinkCriteria
  1. I need to know:
    1. Exactly where, on frm_CreateSurveyWorkOrder, does this code get placed.
    2. The way it is now structured this code exists in limbo, and is not associated with any specific Object.
Reply
  #70  
Old April 1st, 2008, 04:45 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
No, the buttons on the main forms simply bring up the frm_RelatedFiles form which contains the code that makes the application run. (I had to do that because there are at least two forms that use that application)

That is the code that Access generated when I created the button to launch the frm_RelatedFiles form that contains the application to add the different files.

The code should be in the frm_RelatedFiles form. It seems to be working properly. Did i do something wrong?
I'll look at it again later today.
Reply
  #71  
Old April 1st, 2008, 06:14 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

Thanks ADezii, you're the best!

Quote:
Originally Posted by ADezii
I'll look at it again later today.
Reply
  #72  
Old April 1st, 2008, 06:31 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
Thanks ADezii, you're the best!
You are quite welcome, truthlover. Now, In Post #63, replace Line #38 with:
Expand|Select|Wrap|Line Numbers
  1. Forms!frm_RelatedFiles!subfImages.Form.Requery
Reply
  #73  
Old April 1st, 2008, 09:21 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

Did it and it's working great. Thanks!

Now what?

Quote:
Originally Posted by ADezii
You are quite welcome, truthlover. Now, In Post #63, replace Line #38 with:
Expand|Select|Wrap|Line Numbers
  1. Forms!frm_RelatedFiles!subfImages.Form.Requery
Reply
  #74  
Old April 2nd, 2008, 08:39 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

So is there a way, now, to get the report to print multiple image files without having two pages print for each image file selected? Currently, if more than one image file is chosen, the work order form prints, followed by one image, then it prints again followed by the next image etc.

Thanks!

Quote:
Originally Posted by truthlover
Did it and it's working great. Thanks!

Now what?
Reply
  #75  
Old April 2nd, 2008, 11:20 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 60
Posts: 4,817
Default

Quote:
Originally Posted by truthlover
So is there a way, now, to get the report to print multiple image files without having two pages print for each image file selected? Currently, if more than one image file is chosen, the work order form prints, followed by one image, then it prints again followed by the next image etc.

Thanks!
That may be a problem, let me think on that one for awhile.
Reply
  #76  
Old April 3rd, 2008, 01:51 PM
truthlover's Avatar
Member
 
Join Date: Dec 2007
Posts: 107
Default

Ok, thanks.

Have a great weekend.

Quote:
Originally Posted by ADezii
That may be a problem, let me think on that one for awhile.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.