Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 11-15-2006, 03:17 PM   #1
Mark-BES
Registered User
 
Join Date: Nov 2004
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Mark-BES is on a distinguished road
Question Compile error: variable not defined

Hi,

I am a vba novice and in need of expert advise/suggestions:

I have a products database. I wanted to show an image of the product (that users can update) on the form. The example used in the Employee form of the Northwind database fits my needs perfectly.

I have copied/pasted all the code into my form and set all the required "On Click" "After update" settings to [Event procdure] but am getting a compile error (see attached image). If you need all the code it is listed at the bottom of this thread Any ideas on what I have not done?

They say a little knowledge is a dangerous thing!!!


code:

Option Compare Database
Option Explicit
Dim path As String

Private Sub AddPicture_Click()
' Use the Office File Open dialog to get a file name to use
' as an employee picture.
getFileName
End Sub

Private Sub Form_RecordExit(Cancel As Integer)
' Hide the errormsg label to reduce flashing when navigating
' between records.
errormsg.Visible = False
End Sub

Private Sub RemovePicture_Click()
' Clear the file name for the employee record and display the
' errormsg label.
Me![ImagePath] = ""
hideImageFrame
errormsg.Visible = True
End Sub

Private Sub Form_AfterUpdate()
' Requery the ReportsTo combo box after a record has been changed.
' Then, either show the errormsg label if no file name exists for
' the employee record or display the image if there is a file name that
' exists.
On Error Resume Next
showErrorMessage
showImageFrame
If (IsRelative(Me!ImagePath) = True) Then
Me![ImageFrame].Picture = path & Me![ImagePath]
Else
Me![ImageFrame].Picture = Me![ImagePath]
End If
End Sub

Private Sub ImagePath_AfterUpdate()
' After selecting an image for the employee, display it.
On Error Resume Next
showErrorMessage
showImageFrame
If (IsRelative(Me!ImagePath) = True) Then
Me![ImageFrame].Picture = path & Me![ImagePath]
Else
Me![ImageFrame].Picture = Me![ImagePath]
End If
End Sub
Private Sub Form_Current()
' Display the picture for the current employee record if the image
' exists. If the file name no longer exists or the file name was blank
' for the current employee, set the errormsg label caption to the
' appropriate message.
Dim res As Boolean
Dim fName As String

path = CurrentProject.path
On Error Resume Next
errormsg.Visible = False
If Not IsNull(Me!Photo) Then
res = IsRelative(Me!Photo)
fName = Me![ImagePath]
If (res = True) Then
fName = path & "\" & fName
End If

Me![ImageFrame].Picture = fName
showImageFrame
Me.PaintPalette = Me![ImageFrame].ObjectPalette
If (Me![ImageFrame].Picture <> fName) Then
hideImageFrame
errormsg.Caption = "Picture not found"
errormsg.Visible = True
End If
Else
hideImageFrame
errormsg.Caption = "Click Add/Change to add picture"
errormsg.Visible = True
End If

End Sub

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

Sub showErrorMessage()
' Display the errormsg label if the image file is not available.
If Not IsNull(Me!Photo) Then
errormsg.Visible = False
Else
errormsg.Visible = True
End If
End Sub

Function IsRelative(fName As String) As Boolean
' Return false if the file name contains a drive or UNC path
IsRelative = (InStr(1, fName, ":") = 0) And (InStr(1, fName, "\\") = 0)
End Function

Sub hideImageFrame()
' Hide the image control
Me![ImageFrame].Visible = False
End Sub

Sub showImageFrame()
' Display the image control
Me![ImageFrame].Visible = True
End Sub
Attached Images
File Type: jpg compile error.JPG (57.5 KB, 242 views)

Mark-BES is offline   Reply With Quote
Old 11-15-2006, 03:40 PM   #2
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,462
Thanks: 51
Thanked 949 Times in 918 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
the msofile etc, sounds like some sort of microsoft office library reference.

is there any help in your source for this code

-----------------------
open a module and then tools/references - its one of those, but theres a lot to choose from without help!
gemma-the-husky is offline   Reply With Quote
Old 11-16-2006, 12:37 AM   #3
Mark-BES
Registered User
 
Join Date: Nov 2004
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Mark-BES is on a distinguished road
Gemma, you were spot on! It now works. Thank you! after typing "msoFileDialogFilePicker" into google I found this on another forum:


Press Alt+F11 to open the VB Editor. In that window, choose menu items
Tools -> References..., then look down the list for Microsoft Office
11.0 Object Library (it's 11.0 for Access 2003, 10.0 for Access 2002;
9.0 for Access 2000, 8.0 for Access 97 -- pick the right one). Put a
check mark in the box next to that reference, then close the dialog.
Now the "mso..." constants should be defined, and your code can use
them.
Dirk Goldgar, MS Access MVP

Found it here: http://www.mcse.ms/message908935.html

Thanks again. I'm so happy!

Mark-BES is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Compile Error: User-defined type not defined grapisarda Modules & VBA 5 10-28-2014 05:31 AM
Backup Utillity - Compile Error: User Defined Type Not Defined dfwcomputer Modules & VBA 17 06-08-2008 01:41 AM
This must be obvious - Compile Error: Label not defined Keith Nichols Modules & VBA 4 02-21-2006 05:05 AM
Compile error: Variables not defined klwu Modules & VBA 3 09-12-2004 08:29 PM
Compile Error / Variable not Defined Tina Brev Modules & VBA 2 01-23-2001 09:16 AM




All times are GMT -8. The time now is 04:14 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World