?
Solved

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

Posted on 2006-11-07
8
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 12

Expert Comment

by:Bob Lamberson
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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