Attachment field and sending email by access (1 Viewer)

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
hi again :)

i have a sending outlook email button in my form with this code

------------
-----------
Private Sub btnSend_Click()
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem

Set oEmail = oApp.CreateItem(olMailItem)

oEmail.To = Me.txtTo
oEmail.Subject = Me.txtSubject
oEmail.Body = Me.txtBody
If Len(Me.txtAttachment) > 0 Then
oEmail.Attachments.Add Me.txtAttachment.Value
End If
With oEmail
If Not IsNull(.To) And Not IsNull(.Subject) And Not IsNull(.Body) Then
.Send
MsgBox "Email Sent!"
Else
MsgBox "Please fill out the required fields."
End If
End With
end sub
--------
---------
who can I adjust the attachment part to make it attache a file/s or a picture/s from an existing field in ?......
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:06
Joined
Oct 29, 2018
Messages
21,474
Hi. The .Attachments.Add method expects a file path. If you’re trying to attach an Attachment field, you’ll have to save it to disk first.
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
Hi. The .Attachments.Add method expects a file path. If you’re trying to attach an Attachment field, you’ll have to save it to disk first.

.......
Hi
I learned this code from YouTube tutorial where there is an attachment button refers to unbounded field where I can follow a bath..:::
It works great regarding sending the email BUT when I go to a new field the same value still appears because it is not bounded to field where it can be stored.....
How can I solve that issue
!!!!!
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:06
Joined
Sep 21, 2011
Messages
14,311
Clear it after you send the email?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:06
Joined
Oct 29, 2018
Messages
21,474
.......
Hi
I learned this code from YouTube tutorial where there is an attachment button refers to unbounded field where I can follow a bath..:::
It works great regarding sending the email BUT when I go to a new field the same value still appears because it is not bounded to field where it can be stored.....
How can I solve that issue
!!!!!

Hi. How do you populate the unbound textbox? Would you never need to send the same attachment to more than one record?
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
Hi. How do you populate the unbound textbox? Would you never need to send the same attachment to more than one record?
-------
hi

each record is a different meeting attachments and data.... and i use email button .....

BTW
the browsing code for the unbound field is
-----
Private Sub btnBrowse_Click()
Dim fileDiag As fileDialog
Dim file As Variant

Set fileDiag = fileDialog(msoFileDialogFilePicker)

fileDiag.AllowMultiSelect = False
If fileDiag.Show Then
For Each file In fileDiag.SelectedItems
Me.Attachment = file


Next
End If
End Sub
-------

it works great but i thought that keeping an attachment field and inserting it in sending email code is better to store the whole data for each meeting.....

----
so, is it better to keep using unbound field and use a code to clear the field?

can i add the cleaingr code in the previous sending email code???

Thanks theDBguy.... and sorry for my mannnnny questions :)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:06
Joined
Oct 29, 2018
Messages
21,474
-------
hi

each record is a different meeting attachments and data.... and i use email button .....

BTW
the browsing code for the unbound field is
-----
Private Sub btnBrowse_Click()
Dim fileDiag As fileDialog
Dim file As Variant

Set fileDiag = fileDialog(msoFileDialogFilePicker)

fileDiag.AllowMultiSelect = False
If fileDiag.Show Then
For Each file In fileDiag.SelectedItems
Me.Attachment = file


Next
End If
End Sub
-------

it works great but i thought that keeping an attachment field and inserting it in sending email code is better to store the whole data for each meeting.....

----
so, is it better to keep using unbound field and use a code to clear the field?

can i add the cleaingr code in the previous sending email code???

Thanks theDBguy.... and sorry for my mannnnny questions :)
Hi. An Attachment field saves a copy of the file with the record but increases the file size of the database. Eventually, you could run out of space. To insert an Attachment into an Access field, the file must be selected from somewhere. What do you do with the original file after you have attached it in Access? If you keep them anyway, then rather than use an unbound Textbox, I would suggest convert it into a bound Textbox and rather than store the file in an Attachment field, simply store the file path to the original file into a Text field, and bind your unbound Textbox to this Text field.
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
Hi. An Attachment field saves a copy of the file with the record but increases the file size of the database. Eventually, you could run out of space. To insert an Attachment into an Access field, the file must be selected from somewhere. What do you do with the original file after you have attached it in Access? If you keep them anyway, then rather than use an unbound Textbox, I would suggest convert it into a bound Textbox and rather than store the file in an Attachment field, simply store the file path to the original file into a Text field, and bind your unbound Textbox to this Text field.
-----
HI
ok, it is reasonable suggestion ....
I'll work on it and hope that I'll face no more problems ^_^

MANY THANKS TheDBguy
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:06
Joined
Oct 29, 2018
Messages
21,474
-----
HI
ok, it is reasonable suggestion ....
I'll work on it and hope that I'll face no more problems ^_^

MANY THANKS TheDBguy
Hi. You're welcome. Please let us know how it goes.
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
Hi. You're welcome. Please let us know how it goes.
----
hi
the sending code works great when I choose only one email
but more than one this error appears
-----
I get the error "Run-time error -2147467259 (80004005)
Outlook does not recognize one or more names"
---
:(
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:06
Joined
Sep 21, 2011
Messages
14,311
Please post ALL the code required to send the email and attachments.

Put the code within code tags using the # icon

----
hi
the sending code works great when I choose only one email
but more than one this error appears
-----
I get the error "Run-time error -2147467259 (80004005)
Outlook does not recognize one or more names"
---
:(
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
Please post ALL the code required to send the email and attachments.

Put the code within code tags using the # icon
---------

Private Sub btnSend_Click()
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem

Set oEmail = oApp.CreateItem(olMailItem)

oEmail.To = Me.txtTo
oEmail.Subject = Me.txtSubject
oEmail.Body = Me.txtBody
If Len(Me.txtAttachment) > 0 Then
oEmail.Attachments.Add Me.txtAttachment.Value
End If
With oEmail
If Not IsNull(.To) And Not IsNull(.Subject) And Not IsNull(.Body) Then
.Send
MsgBox "Email Sent!"
Else
MsgBox "Please fill out the required fields."
End If
End With
end sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:06
Joined
Sep 21, 2011
Messages
14,311
What happened to the code tags?:banghead:

Inspect Me.TxtTo, what does it contain.?
Use a Debug.Print or MSGBOX or hover over it with a breakpoint set.

Report back with that.

Does it only happen if more than one email address.?
Email addresses should be separated with a ;
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
What happened to the code tags?:banghead:

Inspect Me.TxtTo, what does it contain.?
Use a Debug.Print or MSGBOX or hover over it with a breakpoint set.

Report back with that.

Does it only happen if more than one email address.?
Email addresses should be separated with a ;

----

YES

it only happen if more than one email address..... YES emails is separated with a ;
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:06
Joined
Sep 21, 2011
Messages
14,311
So inspect the .To property and see what that contains.

Sounds like a malformed address.?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:06
Joined
Oct 29, 2018
Messages
21,474
So inspect the .To property and see what that contains.

Sounds like a malformed address.?
I agree. Try creating an email manually and copy and paste the content of the Textbox into the address box. What error do you get?
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
I agree. Try creating an email manually and copy and paste the content of the Textbox into the address box. What error do you get?
-----

GREAT IDEA TheDBguy

I created an outlook email manually and copied the email addresses to my DB field ...every thing Worked great :)

I searched for the reason WHY. :( ..... I compered the out look email copied addresses with the DB code ones I discovered that there is a space after ; between the email addresses.......

I modified the code and added that space :eek: ....

THE PROBLEM SOLVED FINALLY ^_^

MANY THANKS
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
So inspect the .To property and see what that contains.

Sounds like a malformed address.?

-----


YES.... you are right

I discovered that a space after ; in the code caused the problem


MANY THANKS TOO ^_^
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:06
Joined
Sep 21, 2011
Messages
14,311
Hmm, I would not have thought that would cause a problem?
I have just tested, in fact Outlook 2007 puts a space after the ; anyway.?

I ensured spaces were either side and the email was sent normally.

Suspect it was a non displayiing character other than a space.

Main thing is you have it working. Well done.:cool:

-----


YES.... you are right

I discovered that a space after ; in the code caused the problem


MANY THANKS TOO ^_^
 

AsMok

IT IS ME ^_^
Local time
Today, 04:06
Joined
Sep 4, 2019
Messages
64
Hmm, I would not have thought that would cause a problem?
I have just tested, in fact Outlook 2007 puts a space after the ; anyway.?

I ensured spaces were either side and the email was sent normally.

Suspect it was a non displayiing character other than a space.

Main thing is you have it working. Well done.:cool:
——-
That what happened.
Instedof ";" I wrote "; ". The problem solved

It seems that outlook reads them as one address 🙄

BTW::
I use Access2013
 

Users who are viewing this thread

Top Bottom