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

how to "Ok" a Form and then launch a Sub 1

Status
Not open for further replies.

bsurfn99

Technical User
Mar 23, 2005
34
US
I am trying to get a form module to call a "public sub" module, and keep getting a "Compile Error: Sub or Function not defined" Error, Any Ideas out there?

my looks like:

private sub cmdCreate_Click() ' This is the command for creating letter in the form module.

'lots of commands here
'ends with the following

Application.ScreenUpdating = True

Unload Send_to_information

Call EmailDocument

End Sub


Sub EmailDocument() ' ask to sent email. 'this is in a module
Dim intResponse As Integer
intResponse = MsgBox("Would you like to email this?", vbYesNo + vbQuestion + vbDefaultButton2, "Title")
If intResponse = vbYes Then
Call SendDocumentInMail
Else
MsgBox "Email NOT sent"
End If
End Sub

Private Sub SendDocumentInMail() ' starts email process

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem



thanks for anyhelp...
 
Exactly which line of code gives the error?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Always specify Public/Private for subs for clarity
 
Thanks Everyone, It was in fact a public/Private issue, I thought I had that set but I was wrong, I do have another how to question now though.

I have an email address txt box in my form that I would like to use in my EmailDocument, how can I get the text information with my current setup.

Under Forms I have:
MainForm ' This is where I have my Email text box

UnderModules I have:
EmailDoc In this module I have
Public Sub EmailDocument() ' this is a message box that confirms if you really want to email the document
Private Sub DumMessage() ' this is the outlook script to email it.

Currently the Sub DumMessage() doesn't work because I have UserName = txtEmailto.Value which is actually located under a MainForm which all the subs are private.

Any Ideas?


Thanks for everyone's help
BsurfN99
 
How about:
Code:
Public Sub DumMessage(address as String)
And when you call it in the form:
Code:
DumMessage(txtEmail.Text)
Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
I apologize I am pretty new to VB, and I'm not following what you are getting at.

What does this combo do?
Public Sub DumMessage(address as String)
DumMessage(txtEmail.text)

And just to clarify, I'm not trying to call it in the form, I'm trying to get the information from a form that is actually already closed.

Thanks again,
BsurfN99
 
MainForm is ok'd/Created that then calls EmailDocument

EmailDocument is a public sub that is really just a messagebox to confirm if you really want to email document. If you ok it, it launches DumMessage.

BsurfN99
 
Sorry, missed clarification you asked for of the code:
Code:
Public Sub DumMessage(address as String)
by placing
Code:
(address as String)
after the name of the sub you can pass it parameters (in this case a string) you can pass it any string (in your case it could be the value of your txtMailto) which you could have saved as a variable before you closed the form.

When you call the sub, you pass it the parameter it is expecting in the brackets.


Harleyquinn

---------------------------------
For tsunami relief donations
 
OK, before you call EmailDocument save the value of txtMailto as a string. If the user clicks yes then call DumMessage (as described above) passing it the variable you have saved. It can then be used throughout the sub whether the form is open or not.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
Thanks, I think I follow what your saying but VB says otherwise, the DumMessage script can't find the emailaddress. Here is what I have...

Under the form I have:
'save email address for future use
Dim EmailAddress As String
EmailAddress = txtEmailto.Value

Under the Modules I have:
Public Sub DumMessage(EmailAddress)

' Get the user name and email address.
With ActiveWindow.Selection
.EndOf Unit:=wdParagraph, Extend:=wdExtend
UserName = EmailAddress


Thanks for the help, sorry I'm so slow....

BsurfN99
 
Sorry, didn't explain myself very well. If you try:
Code:
Public EmailAddress As String
in the module and just use:
Code:
EmailAddress = txtEmailto.Value
in the form then that will work for you.
Everything else you look to have got spot on.

Harleyquinn

---------------------------------
For tsunami relief donations
 
Didn't work....

Under the form I have:
'save email address for future use
EmailAddress = txtEmailto.Value

Under the Modules I have:
Public Sub DumMessage(EmailAddress)

Public EmailAddress As String ' Is this what you mean?
' Get the user name and email address.
With ActiveWindow.Selection
.EndOf Unit:=wdParagraph, Extend:=wdExtend
UserName = EmailAddress

It says that the Public Emailaddress As String is Invalid in Sub or Function....


BsurfN99
 
Code:
Public EmailAddress As String    ' Is this what you mean?
Nearly. Put it at the top of the module (outside of any subs) and then it will work.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
AHHHAAA IT WORKS!!!


Thanks for your patience with me....

BsurfN99
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top