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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Module in a DAP 1

Status
Not open for further replies.

roles40

MIS
Aug 20, 2003
21
US
I am a relatively new Access user in need of some assistance. I have created a module that I need to implement in a DAP. This module emails a notice to me when a command button is clicked. The problem that I am having is that the current code for the command button is in javascript and the module is written in VB. Is there a way to convert to javascript from VB or can I just use the module in the page. I have also created a macro that uses the runcode command, but I couldn't figure out how to use that either. I tried the DoCmd.RunMacro.Email (where email is the user defined macro) but I couldn't get that to work. Here is the code for the module:

Option Compare Database



Dim olApp As Object
Dim subject As String
Dim olMailItem
Dim newMail
Dim newRecipient
Dim mailBody As String

Function SendEMail(void)

subject = "Technical Issue Page"
mailBody = "A new record has been added to the database."

Set olApp = CreateObject("Outlook.Application")
Set newMail = olApp.CreateItem(olMailItem)
Set newRecipient = newMail.Recipients.Add("me@mydomain.com")

With newMail
.subject = subject
.body = mailBody
End With

newMail.send

Set olApp = CreateObject("Outlook.Application")
Set newMail = olApp.CreateItem(olMailItem)
Set newRecipient = newMail.Recipients.Add("me@mydomain.com")

With newMail
.subject = subject
.body = mailBody
End With


newMail.send

olApp.Quit

Set olApp = Nothing
Set newMail = Nothing
Set newRecipient = Nothing

End Function



Public Sub Main()
SendEMail (void)
End Sub

Any help would be appreciated.

Thanks,

Jamie
 
Here's how you send a mail message via a DAP via the onclick event of command button:

<SCRIPT language=vbscript event=onclick for=YourCommandButton>
<!--
Const olMailItem = 0

Dim objOutlk
Dim objMail

Set objOutlk = createObject(&quot;Outlook.Application&quot;)
Set objMail = objOutlk.createItem(olMailItem)

objMail.To = &quot;YourName&quot;
objMail.Subject = &quot;YourSubject
objMail.body = &quot;YourMessage
objMail.send
set objMail = nothing
Set objOutlk = nothing
-->
</SCRIPT>
 
FancyPrairie,
Hey, thanks for the help with the code. I put the code in verbatum from your sample. I am getting an error at runtime. It is as follows:

ActiveX component can't create object: 'Outlook.Application'

This only happens when I am using VBScript, not in VB like the code I posted to begin with.

Any thoughts...is this possibly a setting? If so do you know where I would go to change it?

Thanks again!
Jamie
 
Chances are that your Intranet settings are preventing you from creating an ActiveX object. In Internet Explorer, goto Tools|Internet Options and select the Security tab. Then select the Local Intranet icon, and then select the button Custom Level... Start enabling the various options. Not sure which one you need off hand.
 
Thanks again! You hit it on the head. Two Stars!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top