Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Multiple Images and store their file path and image name in text fields of ms access table 1

Status
Not open for further replies.

AS Mughal

Programmer
Feb 27, 2022
4
PK
Hi
I have an ms access table having 4 text fields to store 4 image path and image names. i use a form to store the image paths and image names in these text fields. For this i use 4 different command buttons to select image from computer and store the image path and image file name in each text field separately.
What i want is that whether i can use just one command button on form to select all the 4 images and store their image path and image name in one go (instead of using 4 command buttons for each of 4 text fields)
the code behind the command button in available in the attached ms access database
as well as as under
Code:
Private Sub Command23_Click()
Dim f As Object
Dim strfile As String
Dim varItem As Variant

Set f = Application.FileDialog(3)
f.allowMultiSelect = True
If f.show Then
For Each varItem In f.selectedItems
strfile = Dir(varItem)

strfolder = Left(varItem, Len(varItem) - Len(strfile))
MsgBox "Folder" & strfolder & vbCrLf & "File: " & strfile
Me.Image_Path1 = strfolder + strfile 'Textfield of table
Next
End If
Set f = Nothing
End Sub
Thanks....
 
 https://www.4shared.com/s/fuhH73p7giq
I'm not sold on your table structure having four repeated fields. What if you have five image paths to store?

Your code could be modified to add a loop counter as long as the fields are named Image_Path1 through Image_Path4. I'm not sure if you could avoid four prompts using the multi-select.

Code:
Private Sub Command23_Click()
  Dim f As Object
  Dim intI as Integer
  Dim strfile As String
  Dim varItem As Variant
  For intI = 1 to 4
    Set f = Application.FileDialog(3)
    f.allowMultiSelect = True
    If f.show Then
      For Each varItem In f.selectedItems
        strfile = Dir(varItem)
        strfolder = Left(varItem, Len(varItem) - Len(strfile))
        MsgBox "Folder" & strfolder & vbCrLf & "File: " & strfile
        Me("Image_Path" & intI) = strfolder + strfile    [COLOR=#4E9A06]'Textfield of table[/color]
      Next
    End If
  Next
Set f = Nothing
End Sub

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Thanks dhookom for the reply
Could not get your code run on my database
But Yes I do have 4 text fields named Image_path1 through Image_path4
And Yes i do want my code to be modified to add a loop counter upto 4 times
The code i showed is just an example for one out of 4 text fields named Image_path1
I would be much grateful if i could get hell to modify the code ...thanks
I have already uploaded my database
 
Duane said:
What if you have five image paths to store?
I am with Duane, what happens then? And that will happen, no matter what your users tell you. You will need to modify your code every time the number of images increase.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Hi Andrzejek
My database requires 4 image paths only
 
Hi dhookom
i tried your code again and it worked fine now.
Bundle of thanks to you.
 
Real live example (unfortunately from my life):
“We need only to keep 4 Projects”, so the table was designed (not by me, and ‘just-in-case’) to hold 6 Projects (Project_1 to Project_6). A few years later, after developing a very complex programing system, business needed to keep 8 Projects. The table was modified (not by me) to keep 12 Projects: added fields Project_7 to Project_12, ‘just in case’ (you never know how many will be needed in the future, right?).
My co-worker had to modify the code where this table was mentioned. She had to change the code in 275 places to accommodate the additional 6 fields. Many, many hours of tedious (unnecessary) work.
To add the insult to injury, this table has a copy of itself to hold different type of Projects, exactly the same structure. After a few weeks in production, when I realized what was going on, I asked: why another table instead of just adding one field to existing table to differentiate the Projects? The answer: Why didn’t you tell me that before? Nobody asked me.

The point is – if somebody does not know how to design a normalized relational data base, they should be kept away from it. By any means necessary. By force, if needed.


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top