Solved

How to get dept and name? Simple qn,urgent pls help!

Posted on 2006-11-07
8
243 Views
Last Modified: 2011-09-20
Hi All..
I have an urgent qn and I'm new to this.

I have 2 textfields and this is how I get the names thru the texfields. I need the sender and department. Only the 2 fields, how do I call for them??

And how come I get errors when i try to compile? it will say sName=Sender is an Error: expected function or variable?
Public Sub sName()
    sName = sender
End Sub
=================================

Dim strMessage

Public sender As String < ---------------
Public department As String < ---------------

Public Sub sName()
    sName = sender
End Sub
Public Sub DeptName()
    DeptName = department
End Sub
Private Sub txtDept_gotFocus()
    If txtDept.Text = "Department" Then
        txtDept.Text = ""
        department = txtDept.Text
    End If
   
End Sub

Private Sub txtDept_LostFocus()
    If txtDept.Text = "" Then
        txtDept.Text = "Department"
        department = txtDept.Text
    End If
   
End Sub

Private Sub txtName_gotFocus()
    If txtName.Text = "Sender" Then
        txtName.Text = ""
        sender = txtName.Text
    End If
End Sub

Private Sub txtName_LostFocus()
    If txtName.Text = "" Then
        txtName.Text = "Sender"
        sender = txtName.Text
    End If
End Sub

====================================

I'm using active X control to embed this form into outlook. however i need to get the fields and write it into the email body. Please anyone teach me how I can embed into the codes as below which is to be included in outlook. Please help urgent..thanks inadvance!

++++++++++++++++++++++++++++++++++++++++++

Dim strMessage
Dim strSubject
cYear = year(Date())
strSubject = " Christmas Card "&cYear

Function Item_Open()
    item.subject = strSubject
End Function


Function AddInfo()
      'colControls.sName        
      'colControls.DeptName      
      Set colControls = Item.GetInspector.ModifiedFormPages("Message")
           'If sender <> "" And _
       ' department <> "" Then
                strMessage = strMessage _
                & "Dear Clients & Friends" & vbCrLf _
                & vbCrLf _
                & "Season's greeings from the Management" & vbCrLf _
                & vbCrLf _
                & "http://www.oceantankers.com/xmas" & cYear & vbCrLf _
                & vbCrLf _
                & "Best regards" & vbCrLf _
                & vbCrLf _ *************(to include sender's name)
                & vbCrLf _*************(to include dept;s name)
            AddInfo = True
           'Else
           ' AddInfo = False
           'End If
     'Set objThisPage = Nothing
     Set colControls = Nothing
End Function

Function Item_Send()
       If AddInfo() = True then
       Item.subject = strSubject
       Item.body = strMessage
       Item.Display
       Item.MessageClass = "IPM.Note"
        End If    
End Function  
0
Comment
Question by:Yannie
8 Comments
 
LVL 12

Expert Comment

by:BobLamberson
ID: 17895441
If I understand what you are doing, all that you need is code in the

Dim strMessage

Public sender As String '< ---------------
Public department As String '< ---------------

Private Sub Text1_Change()

    sender = Text1.Text     ' this fills your variable 'sender'
    Label1 = sender     ' this demonstrates that it is producing a value and putting it into your variable

End Sub

Private Sub text2_change()

    department = Text2.Text ' this fills you variably 'department'
    Label2.Caption = department
End Sub

does this answer your question?
0
 

Author Comment

by:Yannie
ID: 17895689
Hi Bob,

I actually did it...
the code is actually below..under the gotFocus and lostFocus function as i pasted above..

I actually need to embed it into the second portion of my codes under the AddInfo() such that I can drag the sender and dept variable in...the problem here is i'm not sure how i can get the 2 variables in..

Function AddInfo()
   
      Set colControls = Item.GetInspector.ModifiedFormPages("Message")
          If sender <> "" And _               <----------------------how to get the public sender variable in here..
       ' department <> "" Then            <----------------------how to get the public dept variable in here..
                strMessage = strMessage _
                & "Dear Clients & Friends" & vbCrLf _
                & vbCrLf _
                & "Season's greeings from the Management" & vbCrLf _
                & vbCrLf _
                & "http://www.oceantankers.com/xmas" & cYear & vbCrLf _
                & vbCrLf _
                & "Best regards" & vbCrLf _
                & "sender" & vbCrLf _ <----------------------how to print  the public sender variable in here..
                & "dept" & vbCrLf _ <----------------------how to print the public dept variable in here..
            AddInfo = True
           'Else
           ' AddInfo = False
           'End If
       Set colControls = Nothing
End Function

 
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17895713
Function AddInfo()
      Set colControls = Item.GetInspector.ModifiedFormPages("Message")
          If sender <> "" And department <> "" Then        
                strMessage = strMessage _
                & "Dear Clients & Friends" & vbCrLf _
                & vbCrLf _
                & "Season's greeings from the Management" & vbCrLf _
                & vbCrLf _
                & "http://www.oceantankers.com/xmas" & cYear & vbCrLf _
                & vbCrLf _
                & "Best regards" & vbCrLf _
                & sender & vbCrLf _
                & department & vbCrLf _
            AddInfo = True
           'Else
           ' AddInfo = False
           'End If
       Set colControls = Nothing
End Function


0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17895716
Here is an example of combining strings:

dim strMessage as string
dim strName as string
dim strFinal as string

strName = "Brian"
strMessage = "Hello, my name is "
strFinal = strMessage & strName
MsgBox(strFinal)
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17895721
Or you could do something like this:

dim strMessage as string
dim strUser as string
dim strProgrammer as string

strProgrammer = "Brian"
strMessage = "Hello %user_name% my name is %programmer_name%"
strUser = inputbox("Whats your name?")
strMessage = replace(strMessage,"%user_name%",strUser)
strMessage = replace(strMessage,"%programmer_name%",strProgrammer)

msgbox strMessage



Hope that helps...

Brian
0
 

Author Comment

by:Yannie
ID: 17904760
Hi i sort of got the ans already..

I have to add
Set fmCtl = Item.GetInspector.ModifiedFormPages("Message").Controls("CardFormCtl1")
      dept = fmCtl.DeptName
 under the AddInfo() and this works! Thanks guys!
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17964590
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question