openfile dialog question in MS Access

M

mf_sina

Hi!



I don't know what's the problem with this ordeal in ms access. I saw in
northwind.mdb (samples of ms access) a form for employees. Every employee
has an image file for him/herself.

The form has 2 buttons: Add/Change and Remove.

When I click the button Add/Change, an open file dialog pops up and I can
browse for my image. But I tried to design the same thing in my own
database. but it returns an error:

Compile error: Variable not defined (msoFileDialogFilePicker)



even I copied the entire form of customers and even it's table from
northwind.mdb to my databse but it again returns error. Now it seems to me
that there is a component in Northwind.mdb that file dialog works with but
in my database that component doesn't exist and so i see the error.

Now I appreciate if someone could tell me should I import or do something
special to have that component work in my own database.



Sub getFileName()



' Displays the Office File Open dialog to choose a file name

' for the current employee record. If the user selects a file

' display it in the image control.

Dim fileName As String

Dim result As Integer

With Application.FileDialog(msoFileDialogFilePicker)

.Title = "Select Employee Picture"

.Filters.Add "All Files", "*.*"

.Filters.Add "JPEGs", "*.jpg"

.Filters.Add "Bitmaps", "*.bmp"

.FilterIndex = 3

.AllowMultiSelect = False

.InitialFileName = CurrentProject.Path

result = .Show

If (result <> 0) Then

fileName = Trim(.SelectedItems.Item(1))

Me![ImagePath].Visible = True

Me![ImagePath].SetFocus

Me![ImagePath].Text = fileName

Me![FirstName].SetFocus

Me![ImagePath].Visible = False

End If

End With

End Sub
 
A

Allen Browne

The FileDialog object is supplied by the Office library, but I suggest you
don't use it, because:

- It requires an extra reference, which contributes to the possibility of
broken references (so no code works.)

- Your code will not work in older versions of Access.

- Your code will not work in the runtime.

- It does not work at all for the Save As option, even though it appears to
offer this option.

If you want something that works consistently, in all cases, use the API
call demonstrated this link:
http://www.mvps.org/access/api/api0001.htm
It does look a bit daunting if you have never used this kind of code before,
but one you have it working, it's a no brainer whenever you need to use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top