• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

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

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
Yannie
Asked:
Yannie
1 Solution
 
Bob LambersonSoftware EngineerCommented:
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
 
YannieAuthor Commented:
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
 
BrianGEFF719Commented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
BrianGEFF719Commented:
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
 
BrianGEFF719Commented:
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
 
YannieAuthor Commented:
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
 
DarthModCommented:
PAQd, 500 points refunded.

DarthMod
CS Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now