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

Extract and Save File Path

This Thread was split from:
https://bytes.com/topic/access/answe...re-access-form


Hello ADezii,

I am trying to use the cool button you created in a form on my database. I have a place for 6 images and need a button for each. I am not well versed in access and need some help. I can get the form file you posted great but when I copy the code over to the copied button I must be leaving something undone.

Sorry for the crude explanation. Thanks in advance for any help you may have. I can send my form over if necessary.

John
Jan 27 '16 #1
9 3990
Hello ADezii,

I found another one of your excellent articles "Need "Browse for File" Button. I followed your instructions on how to set the reference to the Microsoft Office Object Library. It worked!! I just changed the imageXX to match where I wanted the photo and it popped right in. However when I close the form and reopen its gone. I need to find a way for it to put the path of the photo in the table to save it.

I have 6 image boxes on my form and each one has the control source linked to a text field in a table. I have created six of your buttons and edited the code for each button to pull and load the pictures for each associated image box. I just need to know how to get it to post the path in the text field in the table so that the photos will show up when the form is closed and reopened. I was trying to avoid the embedding process and linking to a folder with the photos.

I also need a delete button to remove the image in case of a mistake or no image is desired for one of the image boxes.
Jan 27 '16 #2
ADezii
8,834 Expert 8TB
I need to find a way for it to put the path of the photo in the table to save it.
  1. The Absolute PATH to the Graphic File is stored in .SelectedItems(1). After the Image is displayed in the Image Control you need to write this Value to a Field in the Table to which your Form is bound.
    Expand|Select|Wrap|Line Numbers
    1. 'Code intentionally omitted
    2. If .Show Then
    3.             'Can due this because AllowMultiSelect = False
    4.             Me![Image1].Picture = .SelectedItems(1)
    5.               CurrentDb.Execute "UPDATE tblPictures SET PicPath = '" & .SelectedItems(1) & "' WHERE [ID] = " & _
    6.                                  Me![ID], dbFailOnError
    7.           End If
    8. 'Code intentionally omitted
  2. In the Current() Event of the Form you need to Load the Graphic into the Image Control using LoadPicture() based on a Unique [ID] Field for each Record.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Current()
    2.   If Not Me.NewRecord Then
    3.     Me![Image1].Picture = LoadPicture(DLookup("PicPath", "tblPictures", "[ID] = " & Me![ID]))
    4.   End If
    5. End Sub
P.S. - The above Code Blocks are 'Air Code' only and has not been tested.
Jan 28 '16 #3
Hello,

Thanks very much for looking at my question. I am afraid that my skills are so poor that I don't quite know where to past the code. I need to study and keep trying to see if I can get the info into the correct place.

I went to the form properties and created an on current - event procedure and pasted the code you included for part #2. I need to understand how to enter the table name and field identifier.

I don't have a clue where to put the code in item #1?

Thanks!
Jan 28 '16 #4
ADezii
8,834 Expert 8TB
I am a little confused as to the exact nature of your request. Kindly Upload a copy of your Database stripped of any sensitive information.
Feb 1 '16 #5
Hello ADezii,

Thanks for your reply.

I have attached the database and a few photo files for testing.

Thank you very much for your help and code.

I need to get the picture selected with the browse button under each photo to put in the photo and paste the path into the table.

Kindest Regards!
Attached Files
File Type: zip Database.zip (216.7 KB, 136 views)
Feb 1 '16 #6
ADezii
8,834 Expert 8TB
This would be the general, oversimplified, idea on how to store the Absolute File Path of a Graphic File for a specified ID. The Code was only applied to the first Image Control. Download the Attachment to get a better idea of what is going on. The Paths to Graphic Files for IDs should actually be stored in a Related/Child Table.
Expand|Select|Wrap|Line Numbers
  1. 'Must 1st set a Reference to the Microsoft Office XX.X Object Library
  2. Dim varItem As Variant
  3.  
  4. With Application.FileDialog(msoFileDialogFilePicker)
  5.    With .Filters
  6.      .Clear
  7.      .Add "JPEG Files", "*.jpg"
  8.      .Add "Bitmap Files", "*.bmp"
  9.      .Add "Graphic Interchange Format Files", "*.gif"
  10.    End With
  11.        'The Show Method returns True if 1 or more files are selected
  12.        .AllowMultiSelect = False
  13.        .FilterIndex = 1     'Bitmap files
  14.        .ButtonName = "Select Graphic"
  15.        .InitialFileName = vbNullString
  16.        .InitialView = msoFileDialogViewDetails
  17.        .Title = "Load Graphic File!"
  18.           If .Show Then
  19.             'Can due this because AllowMultiSelect = False
  20.             Me![Image86].Picture = .SelectedItems(1)
  21.             CurrentDb.Execute "UPDATE [BJ's Native American Jewelry Collection] SET [FilePath] = '" & _
  22.                                .SelectedItems(1) & "' WHERE [ID] = " & Me![ID]
  23.               MsgBox "The Filepath " & .SelectedItems(1) & " has been stored in [BJ's Native American Jewelry Collection] for [ID] " & _
  24.                       Me![ID] & "."
  25.           End If
  26. End With
Attached Files
File Type: zip Database_Revised_1.zip (32.4 KB, 146 views)
Feb 6 '16 #7
Hello ADezzi,

That example was worth a thousand words! It all works great now.

I had to also make a delete button and I used slightly modified your code. Probably the wrong way but it worked to delete the photos.

Private Sub Command57_Click()

CurrentDb.Execute "UPDATE [BJ's Native American Jewelry Collection] SET [Front Photo] = '" & "' WHERE [ID] = " & Me![ID]

Me.Refresh

End Sub

Also what is the advantage to store the graphic file paths in a Related/Child Table??

Thanks so much for all your help!
Feb 8 '16 #8
ADezii
8,834 Expert 8TB
Also what is the advantage to store the graphic file paths in a Related/Child Table??
To Normalize the Data, eliminate Repeated Fields, and to eliminate Redundancy. Certain Fields in your Table would be repeated for every Graphic File PATH stored which is not very efficient and definitely violates the concept of Normalization. When I get a chance, I will create a Normalized Version of your DB for you, but it will not be for a few days. Good Luck with your Project.
Feb 8 '16 #9
Wow! Thanks!

Did the code I used above look OK for the delete button? It seems to work but I don't want to have any cause any problems down the line.

Looks like snow is on the way for us both again! I am in Maryland.
Feb 8 '16 #10

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

Similar topics

2
by: Kenneth McDonald | last post by:
I have a need to customize the output of Python error tracebacks, and to that end I've implemented my own sys.excepthook function. However, one remaining problem that I'm having is the information...
2
by: Teis Draiby | last post by:
(Using C#) Question 1: Is there an easy build-in support for determining wether a given file path is 1) A valid file path (Only legal characters) 2) The file exists 3) The path exists
1
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
3
by: Rudy | last post by:
Hello! I know you can save the file path to SQL from where you took a file from, like c:/documents.mypictures. And you would use the sFileName = browsefile.PostedFile.FileName But if I want...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
1
by: pbrown | last post by:
Hi, I'm using VB.net 2003, and I have a problem. I need a way of saving a file directly to the desktop, without hardcoding the direct path to the desktop into the program. For example, I'm trying...
0
xtianixm
by: xtianixm | last post by:
hola everyone, how can i save a file path into mysql database without removing the '\' im using XAMPP for my database or phpmyadmin then when i try to insert a file path (ex....
2
by: minn | last post by:
Hi, Is it possible to save local system file path in php session; I explain that i want to achieve: A user selects image files from his computer in "A" web page , when a user goes to "B"...
0
by: maheen khan | last post by:
basically i extracted some attributes of file(name, file type, path etc) present in a directory and listed them in a c++ file, now i want to extract the file path only so that i can use it as an...
3
by: Shem K | last post by:
Hi guys. I'm referring to the insight by Rabbit on this link: http://bytes.com/topic/data-management/answers/949084-how-export-all-attachments-access-save-external-media and by jforbes on this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: 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...

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.