Need "Browse for File" button |

February 13th, 2008, 03:46 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| | 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
| 
March 11th, 2008, 01:59 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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: - Allow you to select Multiple Files.
- Check every Selected File, and if it is one of the specified Formats, dynamically loads its Path into an Array.
- The prior contents of the Array are Preserved and it is Re-dimensioned.
- All the Selected File Paths are now contained in the Array arrsGraphicFiles().
- List all these Files and their Paths to the Immediate Window.
- To test the code, I selected hundreds of Files in the Windows Directory, 6 of which were of a Graphic nature (*.bmp).
- The results are listed below, as well as the code.
-
Dim fdg As FileDialog, vrtSelectedItem As Variant
-
Dim strSelectedFile As String, strImagePath As String
-
Dim intCounter As Integer, arrsGraphicFiles() As String
-
-
Set fdg = Application.FileDialog(msoFileDialogFilePicker)
-
-
intCounter = 0
-
-
With fdg
-
.AllowMultiSelect = True
-
.InitialView = msoFileDialogViewDetails
-
If .Show = -1 Then
-
For Each vrtSelectedItem In .SelectedItems
-
Select Case Right$(vrtSelectedItem, 4)
-
Case ".wmf", ".emf", ".dib", ".bmp", ".ico", ".gif", ".jpg"
-
intCounter = intCounter + 1
-
ReDim Preserve arrsGraphicFiles(intCounter) 'Redimension and Preserve
-
arrsGraphicFiles(intCounter) = vrtSelectedItem
-
Case Else
-
End Select
-
Next vrtSelectedItem
-
Else 'The user pressed Cancel.
-
End If
-
End With
-
-
Set fdg = Nothing
-
-
'Display the Selected/Graphic Files
-
For intCounter = 1 To UBound(arrsGraphicFiles)
-
Debug.Print arrsGraphicFiles(intCounter)
-
Next
OUTPUT: -
C:\WINDOWS\Prairie Wind.bmp
-
C:\WINDOWS\Rhododendron.bmp
-
C:\WINDOWS\River Sumida.bmp
-
C:\WINDOWS\Santa Fe Stucco.bmp
-
C:\WINDOWS\Soap Bubbles.bmp
-
C:\WINDOWS\Zapotec.bmp
| | 
March 11th, 2008, 02:43 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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.
| 
March 11th, 2008, 06:27 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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. | | 
March 11th, 2008, 11:33 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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! | - What is the name of your Primary/Main Table, the Table for which the Attachment Table, will be a Child to?
- ([Primary Table].[Primary Key]{1} ==> [Child Table].[Foreign Key[{MANY})
- What is the Primary Key Field of the Main Table?
- What is the Data Type of the Primary Key Field?
- List the Fields and their Data types in thia Main Table.
- Does your Main Form have the Main Table as its Record Source?
- What is the name of your Main Form?
- For now, create the Child Table and Name it tblAttachments. It should consist of the following Fields:
- [AttachID] - (AutoNumber) - {Primary Key}
- [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).
- [File] - (HyperLink) - [enables Link to selected File(s)].
| 
March 12th, 2008, 04:23 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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 - What is the name of your Primary/Main Table, the Table for which the Attachment Table, will be a Child to?
- ([Primary Table].[Primary Key]{1} ==> [Child Table].[Foreign Key[{MANY})
- What is the Primary Key Field of the Main Table?
- What is the Data Type of the Primary Key Field?
- List the Fields and their Data types in thia Main Table.
- Does your Main Form have the Main Table as its Record Source?
- What is the name of your Main Form?
- For now, create the Child Table and Name it tblAttachments. It should consist of the following Fields:
- [AttachID] - (AutoNumber) - {Primary Key}
- [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).
- [File] - (HyperLink) - [enables Link to selected File(s)].
| | 
March 12th, 2008, 08:19 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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.
| 
March 12th, 2008, 08:54 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
Absolutely.
Thanks! Quote: |
Originally Posted by ADezii Give me a little time to digest everything, so I can figure out the best approach. | | 
March 14th, 2008, 11:53 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| |
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:- 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!
-
Private Sub AddGraphicLinks(strFileName As String, lngID As Long)
-
Dim MyDB As Database
-
Dim MyRS As Recordset
-
-
Set MyDB = CurrentDb
-
Set MyRS = MyDB.OpenRecordset("tblImages", dbOpenDynaset)
-
-
With MyRS
-
.AddNew
-
![SurveyWorkOrderID] = lngID
-
![Link] = strFileName & "#" & strFileName
-
.Update
-
End With
-
-
MyRS.Close
-
Set MyRS = Nothing
-
End Sub
-
Private Sub Command0_Click()
-
On Error GoTo Err_Command0_Click
-
-
Dim fdg As FileDialog
-
Dim vrtSelectedItem As Variant
-
Dim strSelectedFile As String
-
Dim strImagePath As String
-
Dim intCounter As Integer
-
Dim arrsGraphicFiles() As String
-
-
Set fdg = Application.FileDialog(msoFileDialogFilePicker)
-
-
intCounter = 0 'Initialize Counter
-
-
With fdg
-
.AllowMultiSelect = True
-
.InitialView = msoFileDialogViewDetails
-
If .Show = -1 Then
-
'If this is a New Record, then we must force a Save Record before attempting
-
'to add Records to the Images Table. If a problem occurs, such as a Required Field
-
'is missing, the Error Trap will pick it up then Exit the Sub-Routine
-
For Each vrtSelectedItem In .SelectedItems
-
Select Case Right$(vrtSelectedItem, 4)
-
Case ".wmf", ".emf", ".dib", ".bmp", ".ico", ".gif", ".jpg"
-
If Me.NewRecord Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
intCounter = intCounter + 1
-
ReDim Preserve arrsGraphicFiles(intCounter) 'Redimension and Preserve
-
arrsGraphicFiles(intCounter) = vrtSelectedItem
-
Case Else
-
End Select
-
Next vrtSelectedItem
-
Else 'The user pressed Cancel.
-
Exit Sub
-
End If
-
End With
-
-
Set fdg = Nothing
-
-
If intCounter > 0 Then 'at least 1 Graphic File was selected
-
'Display the Selected/Graphic Files
-
For intCounter = 1 To UBound(arrsGraphicFiles)
-
Call AddGraphicLinks(arrsGraphicFiles(intCounter), Me![SurveyWorkOrderID])
-
Debug.Print arrsGraphicFiles(intCounter)
-
Next
-
Forms!frm_CreateSurveyWorkOrder!subfImages.Form.Requery
-
Else
-
MsgBox "No Graphic Files (.wmf, .emf, .dib, .bmp, .ico, .gif, .jpg) were selected", vbExclamation, "No Files Selected"
-
End If
-
-
Exit_Command0_Click:
-
Exit Sub
-
-
Err_Command0_Click:
-
MsgBox Err.Description, vbExclamation, "Error in Command0_Click()"
-
Resume Exit_Command0_Click
-
End Sub
| 
March 17th, 2008, 01:08 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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
| 
March 17th, 2008, 04:05 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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.
| 
March 26th, 2008, 09:26 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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. | | 
March 26th, 2008, 11:11 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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: -
Dim fdg As FileDialog
-
Dim vrtSelectedItem As Variant
-
Dim strSelectedFile As String
-
Dim strImagePath As String
-
Dim intCounter As Integer
-
Dim arrsGraphicFiles() As String
-
-
Set fdg = Application.FileDialog(msoFileDialogFilePicker)
-
-
intCounter = 0 'Initialize Counter
-
-
With fdg
-
.AllowMultiSelect = True
-
.InitialView = msoFileDialogViewDetails
-
If .Show = -1 Then
-
'If this is a New Record, then we must force a Save Record before attempting
-
'to add Records to the Images Table. If a problem occurs, such as a Required Field
-
'is missing, the Error Trap will pick it up then Exit the Sub-Routine
-
For Each vrtSelectedItem In .SelectedItems
-
If Me.NewRecord Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
intCounter = intCounter + 1
-
ReDim Preserve arrsGraphicFiles(intCounter) 'Redimension and Preserve
-
arrsGraphicFiles(intCounter) = vrtSelectedItem
-
Next vrtSelectedItem
-
Else 'The user pressed Cancel.
-
Exit Sub
-
End If
-
End With
-
-
Set fdg = Nothing
-
-
If intCounter > 0 Then 'at least 1 Graphic File was selected
-
'Display the Selected Files
-
For intCounter = 1 To UBound(arrsGraphicFiles)
-
Call AddGraphicLinks(arrsGraphicFiles(intCounter), Me![SurveyWorkOrderID])
-
Debug.Print arrsGraphicFiles(intCounter)
-
Next
-
Forms!frm_CreateSurveyWorkOrder!subfImages.Form.Requery
-
Else
-
MsgBox "No Files Selected were selected", vbExclamation, "No Files Selected"
-
End If
| 
March 31st, 2008, 12:49 AM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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: -
Dim fdg As FileDialog
-
Dim vrtSelectedItem As Variant
-
Dim strSelectedFile As String
-
Dim strImagePath As String
-
Dim intCounter As Integer
-
Dim arrsGraphicFiles() As String
-
-
Set fdg = Application.FileDialog(msoFileDialogFilePicker)
-
-
intCounter = 0 'Initialize Counter
-
-
With fdg
-
.AllowMultiSelect = True
-
.InitialView = msoFileDialogViewDetails
-
If .Show = -1 Then
-
'If this is a New Record, then we must force a Save Record before attempting
-
'to add Records to the Images Table. If a problem occurs, such as a Required Field
-
'is missing, the Error Trap will pick it up then Exit the Sub-Routine
-
For Each vrtSelectedItem In .SelectedItems
-
If Me.NewRecord Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
intCounter = intCounter + 1
-
ReDim Preserve arrsGraphicFiles(intCounter) 'Redimension and Preserve
-
arrsGraphicFiles(intCounter) = vrtSelectedItem
-
Next vrtSelectedItem
-
Else 'The user pressed Cancel.
-
Exit Sub
-
End If
-
End With
-
-
Set fdg = Nothing
-
-
If intCounter > 0 Then 'at least 1 Graphic File was selected
-
'Display the Selected Files
-
For intCounter = 1 To UBound(arrsGraphicFiles)
-
Call AddGraphicLinks(arrsGraphicFiles(intCounter), Me![SurveyWorkOrderID])
-
Debug.Print arrsGraphicFiles(intCounter)
-
Next
-
Forms!frm_CreateSurveyWorkOrder!subfImages.Form.Requery
-
Else
-
MsgBox "No Files Selected were selected", vbExclamation, "No Files Selected"
-
End If
| | 
March 31st, 2008, 01:51 AM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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 | - Where exactly is this Error occurring?
- Try using an absolute reference:
- Forms!frm_CreateSurveyWorkOrder
| 
March 31st, 2008, 01:46 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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 - Where exactly is this Error occurring?
- Try using an absolute reference:
- Forms!frm_CreateSurveyWorkOrder
| | 
March 31st, 2008, 07:12 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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?
| 
March 31st, 2008, 08:01 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
I just sent it. Thanks!! Quote: |
Originally Posted by ADezii Can you send me the Database as a Zip file? | | 
March 31st, 2008, 11:45 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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: -
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "frm_RelatedFiles"
-
-
stLinkCriteria = "[tbl_SurveyWorkOrder.SurveyWorkOrderID]=" & Me![tbl_SurveyWorkOrder.SurveyWorkOrderID]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
- I need to know:
- Exactly where, on frm_CreateSurveyWorkOrder, does this code get placed.
- The way it is now structured this code exists in limbo, and is not associated with any specific Object.
| 
April 1st, 2008, 01:35 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| | 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: -
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "frm_RelatedFiles"
-
-
stLinkCriteria = "[tbl_SurveyWorkOrder.SurveyWorkOrderID]=" & Me![tbl_SurveyWorkOrder.SurveyWorkOrderID]
-
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: -
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "frm_RelatedFiles"
-
-
stLinkCriteria = "[tbl_SurveyWorkOrder.SurveyWorkOrderID]=" & Me![tbl_SurveyWorkOrder.SurveyWorkOrderID]
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
- I need to know:
- Exactly where, on frm_CreateSurveyWorkOrder, does this code get placed.
- The way it is now structured this code exists in limbo, and is not associated with any specific Object.
| | 
April 1st, 2008, 04:45 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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.
| 
April 1st, 2008, 06:14 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
Thanks ADezii, you're the best! Quote: |
Originally Posted by ADezii I'll look at it again later today. | | 
April 1st, 2008, 06:31 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | Quote: |
Originally Posted by truthlover Thanks ADezii, you're the best! | You are quite welcome, truthlover. Now, In Post #63, replace Line #38 with: - Forms!frm_RelatedFiles!subfImages.Form.Requery
| 
April 1st, 2008, 09:21 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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: - Forms!frm_RelatedFiles!subfImages.Form.Requery
| | 
April 2nd, 2008, 08:39 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
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? | | 
April 2nd, 2008, 11:20 PM
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia Age: 60
Posts: 4,817
| | 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.
| 
April 3rd, 2008, 01:51 PM
|  | Member | | Join Date: Dec 2007
Posts: 107
| |
Ok, thanks.
Have a great weekend. Quote: |
Originally Posted by ADezii That may be a problem, let me think on that one for awhile. | |  | | | Thread Tools | Search this Thread | | | | | | | 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.
|