Add Photo Button

C

CCross

I am trying to replicate the employee form from Northwind, but cannot get the
'Add Photo' button to work. When I click on the Add Photo button I get an
error message like 'Compile error and variable not defined.' and the
following code is highlighted. I have copied the entire code from the
employee form into my form and cannot figure out why I am having a problem.

Any help greatly appreciated.

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
 
G

Graham Mandeno

I suspect the code doesn't understand "msoFileDialogPicker". This is
because the definition for that constant is in the Office object library,
and is unknown natively to Access.

To fix this, click on Tools>References (from the VBA code window) and click
on the check box next to:
Microsoft Office x.0 Object Library
(where x is your version number - 9, 10 or 11)

Alternatively, if this is the only reference to that library, you could
cheat and add the constant definition to your own code:
Const msoFileDialogFilePicker = 3

Also, you should always compile your code before you run it with:
Debug>Compile <projectname>

As well as making your code execute faster, because it doesn't need to
compile at run-time, it also checks all your code for errors and reports
them in a much more meaningful way.
 
C

CCross

THANK YOU SO MUCH. IT WORKS!!!

Graham Mandeno said:
I suspect the code doesn't understand "msoFileDialogPicker". This is
because the definition for that constant is in the Office object library,
and is unknown natively to Access.

To fix this, click on Tools>References (from the VBA code window) and click
on the check box next to:
Microsoft Office x.0 Object Library
(where x is your version number - 9, 10 or 11)

Alternatively, if this is the only reference to that library, you could
cheat and add the constant definition to your own code:
Const msoFileDialogFilePicker = 3

Also, you should always compile your code before you run it with:
Debug>Compile <projectname>

As well as making your code execute faster, because it doesn't need to
compile at run-time, it also checks all your code for errors and reports
them in a much more meaningful way.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

CCross said:
I am trying to replicate the employee form from Northwind, but cannot get
the
'Add Photo' button to work. When I click on the Add Photo button I get an
error message like 'Compile error and variable not defined.' and the
following code is highlighted. I have copied the entire code from the
employee form into my form and cannot figure out why I am having a
problem.

Any help greatly appreciated.

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
 

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

Top