attachment

D

Dan @BCBS

I need to save an attachment in a field.

I can code a button to open the Windows "GetOpenFileName" dialog window then
the user finds the file. But I cannot save that file.... I get an error 438:
Object doesn't support this property or method in Form_Open..

In the code below, the Me![doc].Picture is where I am trying to save it..

I posted this eailier but forgot what the subject was:

Private Sub CommFind_Click()
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, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation, "Images not copied"
Cancel = True
End If

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
 
D

Dirk Goldgar

In
Dan @BCBS said:
I need to save an attachment in a field.

I can code a button to open the Windows "GetOpenFileName" dialog
window then the user finds the file. But I cannot save that file....
I get an error 438: Object doesn't support this property or method in
Form_Open..

In the code below, the Me![doc].Picture is where I am trying to save
it..

I posted this eailier but forgot what the subject was:

Private Sub CommFind_Click()
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, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation, "Images not
copied" Cancel = True
End If

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

Is [doc] a bound control? If so, the form's Open event is too soon to
access its data in any way. You have to wait until at least the Load
event, or even better, the Current event.

If this is not a bound control, I'm not sure what's going on, but maybe
waiting until the Load event would work.
 
D

Dirk Goldgar

In
Dan @BCBS said:
I need to save an attachment in a field.

I can code a button to open the Windows "GetOpenFileName" dialog
window then the user finds the file. But I cannot save that file....
I get an error 438: Object doesn't support this property or method in
Form_Open..

In the code below, the Me![doc].Picture is where I am trying to save
it..

I posted this eailier but forgot what the subject was:

Private Sub CommFind_Click()
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, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation, "Images not
copied" Cancel = True
End If

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

Hmm, I read too quicly, and didn't notice that you aren't actually
executing the code in the form's Open event, and your error message is
lying about where it's happening. I think the issue is going to revolve
around what type of control is [doc]? Your code looks okay for an Image
control, but I don't think it will work for other types of control.
 
D

Dan @BCBS

doc is a Bound Object Frame.
I tried plugging this code into On Current,After Update, Before Update.

What suggestion would you have - I just need to give the user the ability to
attach a file or a hyperlink to the form...???

Suggestions?


Dirk Goldgar said:
In
Dan @BCBS said:
I need to save an attachment in a field.

I can code a button to open the Windows "GetOpenFileName" dialog
window then the user finds the file. But I cannot save that file....
I get an error 438: Object doesn't support this property or method in
Form_Open..

In the code below, the Me![doc].Picture is where I am trying to save
it..

I posted this eailier but forgot what the subject was:

Private Sub CommFind_Click()
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, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation, "Images not
copied" Cancel = True
End If

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

Is [doc] a bound control? If so, the form's Open event is too soon to
access its data in any way. You have to wait until at least the Load
event, or even better, the Current event.

If this is not a bound control, I'm not sure what's going on, but maybe
waiting until the Load event would work.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

In
Dan @BCBS said:
doc is a Bound Object Frame.
I tried plugging this code into On Current,After Update, Before
Update.

What suggestion would you have - I just need to give the user the
ability to attach a file or a hyperlink to the form...???

Hyperlinks are completely different from embedded objects. Assuming you
want to store the image file itself in your bound object frame, try
this:

With Me![doc]
.OLETypeAllowed = acOLEEmbedded
.SourceDoc = strFileName
.Action = acOLECreateEmbed
End With

Be aware, though, that image files take up a lot of space in a database.
Most often, it's better to keep the files themselves outside the
database, in some folder on your hard disk, and store just the name (or
name and path) of the file in a text field. Then you can use the form's
Current event to assign the name and path of the image to the Picture
property of an Image control (not a bound object frame). Of course, you
can't do this if the field is to contain object types other than images.

Another alternative is to store just the name and path to the file (of
whatever type) in a text field. Then you can activate the registered
application for it by following it as a hyperlink; e.g.,

Application.FollowHyperlink Me!AttachmentFilePath
 
D

Dan @BCBS

You say it looks ok for an image control.

I have tried changing "doc" to a text box, bound objects, unbound objects,
image etc...

What type of control do you suggest??

Again, everything in this code looks/works good until I try to save the file
to a table..
I get an error 438: Object doesn't support this property or method in



Dirk Goldgar said:
In
Dan @BCBS said:
I need to save an attachment in a field.

I can code a button to open the Windows "GetOpenFileName" dialog
window then the user finds the file. But I cannot save that file....
I get an error 438: Object doesn't support this property or method in
Form_Open..

In the code below, the Me![doc].Picture is where I am trying to save
it..

I posted this eailier but forgot what the subject was:

Private Sub CommFind_Click()
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, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose the Compressed Image File")
If Len(strPathAndFile) > 0 Then
Me![doc].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", vbExclamation, "Images not
copied" Cancel = True
End If

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

Hmm, I read too quicly, and didn't notice that you aren't actually
executing the code in the form's Open event, and your error message is
lying about where it's happening. I think the issue is going to revolve
around what type of control is [doc]? Your code looks okay for an Image
control, but I don't think it will work for other types of control.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

In
Dan @BCBS said:
You say it looks ok for an image control.

I have tried changing "doc" to a text box, bound objects, unbound
objects, image etc...

What type of control do you suggest??

Did you see my message posted on August 17th?
 
D

Dan @BCBS

Yes
I took your suggestion and attempted to save a link instead of the actual
file.
But I could not figure out where to add the code you suggested into my code:
Application.FollowHyperlink Me!AttachmentFilePath
 
D

Dirk Goldgar

In
Dan @BCBS said:
Yes
I took your suggestion and attempted to save a link instead of the
actual file.
But I could not figure out where to add the code you suggested into
my code: Application.FollowHyperlink Me!AttachmentFilePath

You would execute that line, or one like it, whenever you want to open
up the "attachment" in its associated application. I can't say what
event that would be, but one likely possibility is that you would want
to do it when the user double-clicks on the text box displaying the
path. So then you'd have an event procedure for that control looking
something like this:

'----- start of example code -----
Private Sub AttachmentFilePath_DblClick(Cancel As Integer)

If IsNull(Me!AttachmentFilePath) Then
' no attachment; do nothing
Else
Application.FollowHyperlink Me!AttachmentFilePath
End If

End Sub
'----- end of example code -----
 
D

Dan @BCBS

I'll give it a try. Thanks

Dirk Goldgar said:
In

You would execute that line, or one like it, whenever you want to open
up the "attachment" in its associated application. I can't say what
event that would be, but one likely possibility is that you would want
to do it when the user double-clicks on the text box displaying the
path. So then you'd have an event procedure for that control looking
something like this:

'----- start of example code -----
Private Sub AttachmentFilePath_DblClick(Cancel As Integer)

If IsNull(Me!AttachmentFilePath) Then
' no attachment; do nothing
Else
Application.FollowHyperlink Me!AttachmentFilePath
End If

End Sub
'----- end of example code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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

Attach File 4
Stripping file name from Path... 2
"Variable Not Defined" 6
Uploading a Picture 1
Copying a File using API 1
code problem 6
acOLECreateLink 0
Tweeking API Code 2

Top