code problem

J

Jon

Hi,
I have a form for registering new employee. In this form there is a button
for adding the path of the pic of the employee
I put the below code in the event of on click
But when I run the form that shows me there is a wrong in the line as follows
strFilter = ahtaddfilteritem(strFilter, "Images Files",
"*.gif;*.jpeg;*.jpg;*.bmp;*.tif")
StartDir = "c:\"

Can any body tell me what is wrong with it:

Private Sub cmdUpload_Click()
On Error GoTo cmdUpload_Click_Error
Dim strFilter As String
Dim lngFlags As Long
Dim Docpath, FileName, StartDir, driveletter As String

strFilter = ahtaddfilteritem(strFilter, "Images Files",
"*.gif;*.jpeg;*.jpg;*.bmp;*.tif")
StartDir = "c:\"
Docpath = ahtCommonFileOpenSave(InitialDir:=StartDir,
Filter:=strFilter, FilterIndex:=3, flags:=lngFlags, DialogTitle:="Select
Document")

If Not Docpath = "" Then
FileName = Dir(Docpath)
'Me.imgPath = FileName & "#" & Docpath & "#"
Me.ImagePath = Docpath
End If

On Error GoTo 0
Exit Sub

cmdUpload_Click_Error:

MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: Form_Images frm / imgPath_DblClick"
& vbCrLf & _
"Error Description: " & Err.Description, vbCritical, "An Error has
Occured!"
Resume Next

End Sub
 
R

Rob Parker

Hi Jon,

There doesn't appear to be anything wrong with the line in question
(assuming that the line wrap is due to the newsreader, and your code isn't
missing continuation characters if there's a real line break). That leaves
the function call itself. Do you have that function in a module? It should
contain the following code:

Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String
' Tack a new chunk onto the file filter.
' That is, take the old value, stick onto it the description,
' (like "Databases"), a null character, the skeleton
' (like "*.mdb;*.mda") and a final null character.

If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function

HTH,

Rob
 
J

Jon

yes it is in a module.
where should i put your code ?
If you can put it in my code, I would be appreciated your help
 
J

Jon

Let me give you the massage of the error:
Compile error:
Can't find project or library
And the code below is highlighted:
ahtaddfilteritem
 
R

Rob Parker

Jon,

The code I posted was simply what you would need if you didn't have it
already defined. But since you already have it, you don't need it again.

However, since that's the case, I've now looked a little more closely at
your full code. Your original post said you got an errorand you posted two
lines of code; I assumed it was the first. More likely, it was the second:
StartDir = "c:\"
because of your Dim statement:
Dim Docpath, FileName, StartDir, driveletter As String

VBA requires explicit declaration of each variable, so if you want to define
several string variables in a single Dim statement you need:
Dim Docpath As String, FileName As String, StartDir As String,
driveletter As String

HTH,

Rob

PS. And, if that's not the problem, then I'm out of ideas, and hopefully
someone else will take over here ;-)
 
J

Jon

Sorry, Rob
The code I provided is not in the model
It is in the text box coding
I found the model but also has a problem
 
R

Rob Parker

Jon,

That indicates that you do NOT have the code for the ahtAddFilterItem
function in a module. The code you provided is your code (based on a sample
from elsewhere), which sits in the click event of the command button to find
the image file. However, it calls both the ahtAddFilterItem function, and a
few lines later, the ahtCommonFileOpenSave function. The code for both
these functions (and several internal functions that they require) is
available from the The Access Web site, at
http://www.mvps.org/access/api/api0001.htm), and must be included in a
stand-alone module in your database. You should copy/paste everything from
the Code Start to the Code End lines on that page into a module in your
database, and save it using a name which is not the name of any of the
functions contained in it (I have it saved as a module name APIFunctions).

HTH,

Rob
 

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

Folder access (Access 2003) 1
Attach File 4
attachment 9
Uploading a Picture 1
Copying a File using API 1
acOLECreateLink 0
Stripping file name from Path... 2
Importing excel file using VBA 6

Top