Adding New Image Links Through A Form

GeekyGirl

Registered User.
Local time
Today, 17:43
Joined
Apr 14, 2005
Messages
29
Hello,

I have searched through this forum about images and forms but it seems what I need is the next step...

I have an Image table where I store the location of the image file. In my form, I am able to view each picture with each record perfectly using the directions from the Microsoft Knowledgebase Article titled:

"How to display images from a folder in a form, a report, or a data access page" which can be found here.

Now I want to be able to add a new record through my form which includes the file information for a picture. I saw in samples where you can add a command button to add the picture but I don't know how to code the button so that it opens up a window for me to select the image file from.

Any help would be greatly appreciated!
 
Search this forum, Access help, and/or your object browser for "FileDialog".
Cheers,
 
I used the FileDialog method from a microsoft article but am now getting the following error:

Compile Error: User-defined type not defined

I have verified that the Microsoft Office 10.0 Object Library has been checked in the references.

Here is my code with the error location marked in red:

Private Sub cmdFileDialog_Click()

' This requires a reference to the Microsoft Office 11.0 Object Library.

Dim fDialog As Office.FileDialog
Dim varFile As Variant

' Clear the list box contents.
Me.FileList.RowSource = ""

' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow the user to make multiple selections in the dialog box.
.AllowMultiSelect = False

' Set the title of the dialog box.
.Title = "Please select the image you want"

' Clear out the current filters, and then add your own.
.Filters.Clear
.Filters.Add "Access Databases", "*.MDB"
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "All Files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
' Loop through each file that is selected and then add it to the list box.
For Each varFile In .SelectedItems
Me.ImageName.AddItem varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
 
Sorry, I did a search with "Image" and "Form" and it returned 11 pages of threads.

Did you try the image sample in the other link.

I do sort of remember the issue you mention and never sorted it, thats why I use the code in the sample.

Dave

PS: I have since updated the way the zoom works in my operating databases. Will add it to the sample and post it when I get a chance.
 

Attachments

I have looked at your sample prior to posting but couldn't get the adding of a picture to work right. That is when I found the microsoft knowledgebase article that gave me the code seen above.

Now if I can just figure out the error, I think I'll be OK.

I worked with Access for many years but have never really ventured into the coding aspect of it too much. Since coding is like a foreign language to me right now, I am not knowledgeable enough to be able to debug it to find what I need to change.

BTW - with your example, when you click on Add New Picture, it adds a new record but doesn't bring up the file dialog box. I'm assuming you have it designed so you then have to click on the Change Picture button to actually add the image.

I also tried the coding for the Change Picture button when I first found your sample but experienced errors with that as well when it came to defining OFN. Since the errors seem to mimic one another, it seems to me that there is a problem with the first few lines, it seems to me that my Access program is not processing the code correctly.

I copied and pasted both codes as they are written and only changed the appropriate field names where needed.

So what is causing the error? Or more to the point, what do I need to do to fix it?
 
After reading that people have problems calling up the Microsoft FileDialog, I retried the sample you posted.

I get the error:
Compile Error: User-defined type not defined

with the following line highlighted in the debug mode:
Dim OFN As OPENFILENAME

I'm just about going nuts trying to get this to work. PLEASE HELP!!

And while we're on the topic...can you retrieve more than the path of the file? For instance, can you retrieve the width, height and file size of the file being selected?

I'd be happy with just the path right now but would ideally like the other information so I wouldn't have to look it up and enter it myself in the fields I have created.
 
Last edited:
Never tried to retrieve the size etc.

Can you post a cutdown version?

PS: Are you pasting the OFN module into the modules?

Dave
 
I didn't know about the module. So I went ahead and added that. Now I'm getting a new error.

Download the database file from here

It is the Images form that I am trying to get to work using the Add Picture button.
 
i downloaded you database, it works for me but when i go and change the link where my other pictures are stored. it seems like the other pics stay in the linked pictures area. i have tried to erase them "with the button" but it says there is an error.
 

Users who are viewing this thread

Back
Top Bottom