Can I call a module from within this code?

Franky G

Registered User.
Local time
Today, 23:05
Joined
Feb 6, 2001
Messages
62
Hi,

I have some code which runs when a user clicks a button, which notifies the user (msgbox) that an alert will be sent to the administrator if they elect to continue. If they click Continue, I would like to call a module which sends the email, then continues with the code that runs my query and launches Excel.

I have the module working correctly, I just can't find out how to call it from within this code below. I don't even know if it's possible?! if there is a better way to do this then please advise me. thanks for any help,

FrankyG


Private Sub CmdMonthVals_Click()
If IsNull(Me.p1start) Or IsNull(Me.p1end) Then
msgbox "Both dates are required"
Else
If Me.p1start > Me.p1end Then
msgbox "End Date earlier than Start Date"
Else
On Error GoTo Err_CmdMonthVals_Click
Dim intButSelected As Integer, intButType As Integer
Dim strMsgPrompt As String, strMsgTitle As String

strMsgPrompt = "This action will be logged, and an alert sent to the administrator. Continue?"
strMsgTitle = "Restricted Access"

intButType = vbYesNo + vbInformation + vbDefaultButton2
intButSelected = msgbox(strMsgPrompt, intButType, strMsgTitle)

If intButSelected = vbYes Then

DoCmd.SetWarnings False

'I want to call the SendMail module HERE!!

DoCmd.OpenQuery "QryGraphData", acNormal, acEdit
Call Shell("""C:\Program Files\Microsoft Office\Office\EXCEL.EXE"" ""path to file.xls""", 1)

Exit_CmdMonthVals_Click:
Exit Sub


Err_CmdMonthVals_Click:
msgbox Err.Description
Resume Exit_CmdMonthVals_Click
DoCmd.SetWarnings True
End If

Exit Sub
End If
End If
End Sub
 
I'm assuming that you have a Procedure (Sub/Function) in a module that does the Email. All you need to do is add a line to your code to call this procedure.

Example
You have a Public Function that returns the Month of a Date
Code:
Public Function WhatMonth(ByVal dtDate as Date) as Integer
 Dim iMonth as integer
 iMonth=Month(dtDate)
 WhatMonth=iMonth

End Function


Now you want to call it.

Code:
Dim dDate as Date

dDate=Date()

Msgbox "It is the " & WhatMonth(dDate) & " of the Year"
 
Thanks, managed to figure it yesterday. Made the sendmail code a sub and just inserted the line

Call SendMail

into my code. Works for me anyway!

Cheers!

FrankyG
 

Users who are viewing this thread

Back
Top Bottom