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

Need "Browse for File" button

truthlover
107 100+
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
Feb 13 '08
79 40802
truthlover
107 100+
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 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
Mar 11 '08 #51
ADezii
8,834 Expert 8TB
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.
Mar 11 '08 #52
truthlover
107 100+
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!

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.
Mar 11 '08 #53
ADezii
8,834 Expert 8TB
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)].
Mar 11 '08 #54
truthlover
107 100+
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!



  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)].
Mar 12 '08 #55
ADezii
8,834 Expert 8TB
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.
Mar 12 '08 #56
truthlover
107 100+
Absolutely.

Thanks!

Give me a little time to digest everything, so I can figure out the best approach.
Mar 12 '08 #57
ADezii
8,834 Expert 8TB
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
Mar 14 '08 #58
truthlover
107 100+
Whew is right!

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

Thanks soooo much!

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!
...
Mar 17 '08 #59
ADezii
8,834 Expert 8TB
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.
Mar 17 '08 #60
truthlover
107 100+
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!




You are quite welcome, keep in touch.
Mar 26 '08 #61
ADezii
8,834 Expert 8TB
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!
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
Mar 26 '08 #62
truthlover
107 100+
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


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
Mar 31 '08 #63
ADezii
8,834 Expert 8TB
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
Mar 31 '08 #64
truthlover
107 100+
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"
  1. Where exactly is this Error occurring?
  2. Try using an absolute reference:
    Expand|Select|Wrap|Line Numbers
    1. Forms!frm_CreateSurveyWorkOrder
Mar 31 '08 #65
ADezii
8,834 Expert 8TB
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?
Mar 31 '08 #66
truthlover
107 100+
I just sent it. Thanks!!

Can you send me the Database as a Zip file?
Mar 31 '08 #67
ADezii
8,834 Expert 8TB
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.
Mar 31 '08 #68
truthlover
107 100+
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)
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.
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?

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.
Apr 1 '08 #69
ADezii
8,834 Expert 8TB
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.
Apr 1 '08 #70
truthlover
107 100+
Thanks ADezii, you're the best!

I'll look at it again later today.
Apr 1 '08 #71
ADezii
8,834 Expert 8TB
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
Apr 1 '08 #72
truthlover
107 100+
Did it and it's working great. Thanks!

Now what?

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
Apr 1 '08 #73
truthlover
107 100+
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!

Did it and it's working great. Thanks!

Now what?
Apr 2 '08 #74
ADezii
8,834 Expert 8TB
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.
Apr 2 '08 #75
truthlover
107 100+
Ok, thanks.

Have a great weekend.

That may be a problem, let me think on that one for awhile.
Apr 3 '08 #76
I also want to thank you for this. So much more compact than some of the 'easy' solutions I have seen.

One question

<snip>
Jan 27 '12 #77
NeoPa
32,556 Expert Mod 16PB
Select a File or Folder using the FileDialog Object may prove helpful on this subject.
Jan 28 '12 #78
Truth Lover:
Your code above this section worked great to get the link into the field on my access form, but for some reason it won't stay there once I close the form. If I go to the pdf and select the path and paste it into the field, it stays just fine. But if I use the button I created and the code you wrote above for that button, it only pastes it in there temporarily. How do I get it to stay in that field?
Sep 7 '17 #79
NeoPa
32,556 Expert Mod 16PB
Hi Joni.

One of the reasons (Only one. There are others.) we insist on your creating a new thread for your questions is that those members active in the old thread may well no longer be active. TruthLover was last active here in 2008.

Please post your question as a stand-alone thread in its own right and I'm sure there will be members and experts more than willing to offer you help. It's perfectly permissable to link to a previous thread, or even post, to help explain your question.

Good luck and welcome to Bytes.com.
Sep 8 '17 #80

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

Similar topics

10
by: mike | last post by:
regards: I use Jtidy (api) to translate a HTML file into a "XHTML file". But The "XHTML file" cannot be identified by nokia 6600. Do I miss something important? Or this is Jtidy's weakness or...
0
by: Bill R via AccessMonster.com | last post by:
I have a procedure that runs when you dbl click in a txt box. It runs the docmd.acCmdHyperLink command. I am trying to find a way to have the "Insert Hyperlink" dialog box default to "Browse For"...
2
by: Be Learning | last post by:
How can we compile a entire website (includes "attachment" like *.zip, *.pdf, ...) to only one *.chm file (with index, search)? Please tell me if anyone know. Thanks
1
by: Nicolas B | last post by:
Hi under VS.Net 2003 how can I specify the parameter "Output File" of a library (see Project Property Pages \ Common Properties\General\Project\Output File) I want to change the default...
5
by: Mr Gordonz | last post by:
Hi all, I want to put a button on a page, and when the user clicks it, the standard Windows "Open File" dialogue box opens, and the user can browse/select a file on their PC. Having selected a...
4
by: Mark Rendle | last post by:
Hi I'm writing a page which outputs CSV data for download. It's all working fine, setting ContentType to "text/csv", except when the "Open/Save" dialog appears, the filename shown is...
3
by: Terry Olsen | last post by:
I followed the information in a previous thread, but i'm having problems. I have a couple dropdownlists and a submit button on my form. The user selects choices from the lists and clicks the...
1
by: coosa | last post by:
Hi all, As the topic describes, I'd like to run a batch file using sql server. How do i do it? Thanks in advance
0
by: Greg Larsen | last post by:
How add the "Active File" icon (down arrow), and the "Close" icon (X) next on TabPage in the gray space next to the tabs, so when I click on the X the active Tab closes, and and when I click on the...
3
by: anudu | last post by:
hi, I am developing a system with asp.net, c#, and ajax. I have an excel file in server in "Server.MapPath("ExcelFiles/Test.xls")". I want to make it available to save to the disk in client...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.