Attach File

G

Guest

When a button (CommFind) is clicked the Windows dialog "GetOpenFileName"
appears. The user finds the file he wants to attach and clicks open.
I need that file to be saved to an Object field on the form (doc) but I get
the error 438:Object doesn't support this property or method in Form_Open.

How can I attach this file????????


Private Sub CommFind_Click()
' Purpose : Invokes the Windows Common Dialog GetOpenFileName function to
allow user to choose an image file
' Created/Modified : 8/15/07 By Dan Frisch,
On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
strFilter = ahtAddFilterItem(strFilter, "Compressed Image Files (*.jpg,
*.jff, *.gif, *.tiff )", _
"*.JPG;*.JFF,*.GIF,*.TIF")
' strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
' strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
' MsgBox "You selected: " & strPathAndFile
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation, "Images not copied"
Cancel = True
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
Form_Open", vbExclamation, "Images in Access Example"
Cancel = True
Resume Exit_Sub
End Sub
 
O

OldPro

When a button (CommFind) is clicked the Windows dialog "GetOpenFileName"
appears. The user finds the file he wants to attach and clicks open.
I need that file to be saved to an Object field on the form (doc) but I get
the error 438:Object doesn't support this property or method in Form_Open.

How can I attach this file????????

Private Sub CommFind_Click()
' Purpose : Invokes the Windows Common Dialog GetOpenFileName function to
allow user to choose an image file
' Created/Modified : 8/15/07 By Dan Frisch,
On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
strFilter = ahtAddFilterItem(strFilter, "Compressed Image Files (*.jpg,
*.jff, *.gif, *.tiff )", _
"*.JPG;*.JFF,*.GIF,*.TIF")
' strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
' strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
' MsgBox "You selected: " & strPathAndFile
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation, "Images not copied"
Cancel = True
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
Form_Open", vbExclamation, "Images in Access Example"
Cancel = True
Resume Exit_Sub
End Sub

Your own code is supplying the "in form_open" part of the error
message. Since the error is not in form_open, this is a misleading
error message. Because you are handling the error, we don't know
which line caused it. If you can disable the error handling and rerun
your code, you should be able to figure out which property isn't
supported. An alternative is to put a stop on a line of code (F9) and
trace through the code one step at a time (F8).
 
B

Bob Quintal

What type of control is [doc]?
What field in the table is the control on the form bound?
What type of field is this?

We need this info to attempt to resolve your problem.

Another point is that Access is really bad at storing files in a
table. You will get huge amounts of bloat and possible
corruption. I've been down this road.

An alternative is to just get the filename, extract the file
extension to a variable, create a new file name that should be
in the form of File000001 incremented, then
Filecopy strPathAndFile, newpath & newFilename & fileExtension
where newpath points to a directory created just to store the
copied files.

Once the file is copied, add the original file and newfile names
to the table, so you are storing the location of the file not
the file itself, and use the followHyperLink method to open a
file.

=?Utf-8?B?RGFuIEBCQ0JT?= <[email protected]>
wrote in
When a button (CommFind) is clicked the Windows dialog
"GetOpenFileName" appears. The user finds the file he wants
to attach and clicks open. I need that file to be saved to an
Object field on the form (doc) but I get the error 438:Object
doesn't support this property or method in Form_Open.

How can I attach this file????????


Private Sub CommFind_Click()
' Purpose : Invokes the Windows Common Dialog
GetOpenFileName function to allow user to choose an image file
' Created/Modified : 8/15/07 By Dan Frisch,
On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
strFilter = ahtAddFilterItem(strFilter, "Compressed Image
Files (*.jpg,
*.jff, *.gif, *.tiff )", _
"*.JPG;*.JFF,*.GIF,*.TIF")
' strFilter = ahtAddFilterItem(strFilter, "dBASE Files
(*.dbf)", "*.DBF")
' strFilter = ahtAddFilterItem(strFilter, "Text Files
(*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)",
"*.*") strPathAndFile =
ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
' MsgBox "You selected: " & strPathAndFile
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation,
"Images not copied" Cancel = True
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the
variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description & "
in
Form_Open", vbExclamation, "Images in Access Example"
Cancel = True
Resume Exit_Sub
End Sub
 
G

Guest

doc - is an object bound frame, it is the field I want to store the file.
The button with the code below is just a command button.

If I understand you correctly: Your saying, change the code below to copy
the file name into a table and increment a tracking number like 001, 002 etc.

Saving just the file name would be fine.
Could you show me how to change this code to copy the file name instead if
the file.
I tried that way first and ended up having to copy the entire file.






Bob Quintal said:
What type of control is [doc]?
What field in the table is the control on the form bound?
What type of field is this?

We need this info to attempt to resolve your problem.

Another point is that Access is really bad at storing files in a
table. You will get huge amounts of bloat and possible
corruption. I've been down this road.

An alternative is to just get the filename, extract the file
extension to a variable, create a new file name that should be
in the form of File000001 incremented, then
Filecopy strPathAndFile, newpath & newFilename & fileExtension
where newpath points to a directory created just to store the
copied files.

Once the file is copied, add the original file and newfile names
to the table, so you are storing the location of the file not
the file itself, and use the followHyperLink method to open a
file.

=?Utf-8?B?RGFuIEBCQ0JT?= <[email protected]>
wrote in
When a button (CommFind) is clicked the Windows dialog
"GetOpenFileName" appears. The user finds the file he wants
to attach and clicks open. I need that file to be saved to an
Object field on the form (doc) but I get the error 438:Object
doesn't support this property or method in Form_Open.

How can I attach this file????????


Private Sub CommFind_Click()
' Purpose : Invokes the Windows Common Dialog
GetOpenFileName function to allow user to choose an image file
' Created/Modified : 8/15/07 By Dan Frisch,
On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
strFilter = ahtAddFilterItem(strFilter, "Compressed Image
Files (*.jpg,
*.jff, *.gif, *.tiff )", _
"*.JPG;*.JFF,*.GIF,*.TIF")
' strFilter = ahtAddFilterItem(strFilter, "dBASE Files
(*.dbf)", "*.DBF")
' strFilter = ahtAddFilterItem(strFilter, "Text Files
(*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)",
"*.*") strPathAndFile =
ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
' MsgBox "You selected: " & strPathAndFile
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation,
"Images not copied" Cancel = True
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the
variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description & "
in
Form_Open", vbExclamation, "Images in Access Example"
Cancel = True
Resume Exit_Sub
End Sub
 
B

Bob Quintal

=?Utf-8?B?RGFuIEBCQ0JT?= <[email protected]>
wrote in
doc - is an object bound frame, it is the field I want to
store the file. The button with the code below is just a
command button.

If I understand you correctly: Your saying, change the code
below to copy the file name into a table and increment a
tracking number like 001, 002 etc.

Saving just the file name would be fine.
Could you show me how to change this code to copy the file
name instead if the file.
I tried that way first and ended up having to copy the entire
file.
Doc is the control on the form. What type of field is it bound
to in the table? It should be an OLE type, iirc.

Your function returns the file name into the
variable strPathAndFile. Just set the textbox that is bound to
the filename field.
me.txtFillname = strPathAndFile

that's all that's necessary.

I do think that you want to copy the file to a secure location,
renaming it to File001.jpg because users are apt to clean
directories, move files and delet older ones. If you just store
the existing path and name you soon will have broken links.

To do this correctly, you first want to get the file's
extension.

For x=len(strPathandFile to 1 step -1
if mid(strPathandFile,X,1) = "." then
exit for
else
stFileExt = mid(strPathandFile,X)
end if
if len(stfileExt = len(strPathAndFile then
StfileExt = ""
end if
'Now find the next trackingNumber.
'There are so many ways....Up to you.
' and store it to stNewFileName.

' now actually copy the file to the safe directory.
Filecopy strPathAndFile, "C:\Secure\" & stnewfilename & "."
&stFileExt
'save the new filename to the table.

Good luck.



Bob Quintal said:
What type of control is [doc]?
What field in the table is the control on the form bound?
What type of field is this?

We need this info to attempt to resolve your problem.

Another point is that Access is really bad at storing files
in a table. You will get huge amounts of bloat and possible
corruption. I've been down this road.

An alternative is to just get the filename, extract the file
extension to a variable, create a new file name that should
be in the form of File000001 incremented, then
Filecopy strPathAndFile, newpath & newFilename &
fileExtension where newpath points to a directory created
just to store the copied files.

Once the file is copied, add the original file and newfile
names to the table, so you are storing the location of the
file not the file itself, and use the followHyperLink method
to open a file.

=?Utf-8?B?RGFuIEBCQ0JT?= <[email protected]>
wrote in
When a button (CommFind) is clicked the Windows dialog
"GetOpenFileName" appears. The user finds the file he
wants to attach and clicks open. I need that file to be
saved to an Object field on the form (doc) but I get the
error 438:Object doesn't support this property or method in
Form_Open.

How can I attach this file????????


Private Sub CommFind_Click()
' Purpose : Invokes the Windows Common Dialog
GetOpenFileName function to allow user to choose an image
file ' Created/Modified : 8/15/07 By Dan Frisch,
On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
strFilter = ahtAddFilterItem(strFilter, "Compressed
Image Files (*.jpg,
*.jff, *.gif, *.tiff )", _
"*.JPG;*.JFF,*.GIF,*.TIF")
' strFilter = ahtAddFilterItem(strFilter, "dBASE
Files (*.dbf)", "*.DBF")
' strFilter = ahtAddFilterItem(strFilter, "Text
Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files
(*.*)", "*.*") strPathAndFile =
ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags,
_ DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
' MsgBox "You selected: " & strPathAndFile
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation,
"Images not copied" Cancel = True
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the
variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description
& " in
Form_Open", vbExclamation, "Images in Access Example"
Cancel = True
Resume Exit_Sub
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

Similar Threads

attachment 9
Stripping file name from Path... 2
"Variable Not Defined" 6
Uploading a Picture 1
code problem 6
Folder access (Access 2003) 1
Copying a File using API 1
All file types in browse to file path? 1

Top