?
Solved

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

Posted on 2006-11-07
8
Medium Priority
?
253 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
7 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 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