PDA

View Full Version : Linking two procedures



Mr Nice Guy
12-16-2005, 09:38 PM
Hi, Im fairly new at VB programming. I am using two separate procedures which I now wish to link. The first is a form that i created which stores inputted values into a worksheet(This program works fine on its own). I was also playing around with a code previously posted that I wish to call when the final button on the form is activated. This code (named MailITNow) is one that uses outlook to email a list of people stored in the worksheet (also works fine on its own). The problem is occuring when I try to call the second program from the first one.

This is what I was using to call the second procedure

Private Sub cmdInitiate_Click()
.
.
.
.
.
ActiveWorkbook.Sheets("contacts").Activate
Call MailItNow
End Sub

I placed the MailItNow procedure (which I found on this forum and manipulated a bit) in a separate module and it uses the same worksheet that was activated above.

The procedure starts with declarations like this
Sub MailItNow()
'--- Set up the Outlook objects.
Dim objOutlook As Outlook.Application ******************
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
'--- Declare global variables to be used in each subroutine.
Dim Address As String
Dim Name As String
Dim Message As String
'--- Declare variables.
Dim X As Integer
Dim TempAddress As String
Dim TempName As String
.
.
.
End Sub

When I go to run this it gives me the following error
for the line marked with ******************** above
compile Error
user-defined type not defined

I have tried to put this procedure in the same module as the procedure calling it, and I have also tried moving the declarations inside the procedure, but still get the same error message...what am I doing wrong?
Please Help!!!

mdmackillop
12-17-2005, 03:47 AM
Hi,
Welcome to VBAX
I think you just need to add a reference to Microsoft Outlook using Tools/References in the VB editor.
Regards
MD