Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email 1

Status
Not open for further replies.

cherrielwy

IS-IT--Management
Jul 30, 2003
27
0
0
MY
Hi,

I want to email just the id in a form after i fill in all the data in the form. How can i email that id automatically but not in attachment

 
Code:
Private Sub DIRECTEMAIL_DblClick(Cancel As Integer)
    Dim objOutlook As Object
    Dim objItem As Object
    Dim strMailTo  As String
    Dim strName
    Dim strtype
    Dim iIndid
    
    On Error GoTo starterror
    

    'Create a Microsoft Outlook object.
    Set objOutlook = CreateObject("Outlook.Application")

    'Create and open a new email for input.
    Set objItem = objOutlook.CreateItem(olMailItem)
    DIRECTEMAIL.SetFocus
    strMailTo = DIRECTEMAIL.Text
    If strMailTo <> &quot;&quot; Then 'Not IsNull(strMailTo) Or
    
    objItem.To = strMailTo
objItem.Body = IDcontrol
Code:
    objItem.Display
    End If

    'Quit Microsoft Outlook.
    Set objOutlook = Nothing


ExitHere:
    Exit Sub

starterror:
    Select Case Err.Number
        Case Else
            MsgBox &quot;An error occured: &quot; & Err.Number _
            & &quot; &quot; & Err.Description
    End Select
    
End Sub
[code]

refernce for Outlook needs to be added
 
Hi,

thank you for ur coding,but i cannot make it work properly,how? Actually, i having a form(frmSRFDetail) that need data entry. After all the data were input in the form,i need to send just the NRF_ID for manager reference? Can i create a command button that when i click on it, the NRF_ID will send to my manager automatically?Thank You


 
When you say you cant get it to work, what stops it working?
What error do you get and what line causes it?
Did you include the reference for Outlook?
If you are using a different Email system than outlook you might need to use a different reference, the object browser should help you see what substititues to use in the code.

This code could be triggered on a button click event. The SendObject key word is worth looking at too.
 
The Line&quot;Set objItem = objOutlook.CreateItem(olMailItem)&quot; got error and line &quot;strMailTo = DIRECTEMAIL.Text&quot; cannot find the command. So How can i correct the error? Thank You

 
Right, the line you quoted collects a value from a control on my form it is a field called DIRECTMAIL on your app it will be the control or record you have the email address stored in.

let me know if you get stuck elsewhere
 
HI,


I still cannot email my NRF ID to my manager using a command button in my form.Can anybody help coz i need to type the NRF_ID by myself now and i just want to send this to two same person every times.can it work. Thank You
 
If you want it to go to the same 2 ppl everytime you can hard code their email address's in.

see below in bold


Private Sub DIRECTEMAIL_DblClick(Cancel As Integer)
Dim objOutlook As Object
Dim objItem As Object
Dim strMailTo As String
Dim strName
Dim strtype
Dim iIndid

On Error GoTo starterror


'Create a Microsoft Outlook object.
Set objOutlook = CreateObject(&quot;Outlook.Application&quot;)

'Create and open a new email for input.
Set objItem = objOutlook.CreateItem(olMailItem)

strMailTo = &quot;email@you.com, email2@your.com&quot;
'You can remove the if statement aswell if you do it this way

objItem.To = strMailTo
objItem.Body = IDcontrol
objItem.Display

'Quit Microsoft Outlook.
Set objOutlook = Nothing


ExitHere:
Exit Sub

starterror:
Select Case Err.Number
Case Else
MsgBox &quot;An error occured: &quot; & Err.Number _
& &quot; &quot; & Err.Description
End Select

End Sub
 
Hi marksnow ,

I copy the code that u give and change the IDcontrol to Forms![frmSRFDetail]![NRF_ID], i cannot run it.It prompt out a eeror msg &quot;user-defined type not defined&quot;. How can i solve it? Thank You.


Cherrie
 
olMailItem will only be resolved if you have a reference set to Outlook in Access.

I'd suggest changing it to:
Set objItem = objOutlook.CreateItem(0)

Another option would be to use SendObject (sespecially if you use some other email program instead of Outlook):

Docmd.SendObject ,,,Me![EmailAddressBox],,,Me![SubjectBox],me![BodyBox],False


Good luck



[pipe]
Daniel Vlas
Systems Consultant

 
Daniel

Can you copy and paste you code in here so we can have a look??

Cheers
Mark
 
How can this be done avoiding the Outlook security pop-up when sending email?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top