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

Added Command Button To Reply Message

Status
Not open for further replies.

RAxel

MIS
Sep 8, 2005
121
US
I have created the subject textbox to be read only when a person replies to it, so it obviously won't be changed. What I want to do is add another textbox, right beside the subject and a button.

Inside this textbox (which I've called txtPassword), I want someone to enter the password and hit the button (btnPassword). If the password is correct, I want the subject to become editable. Basically, unchecking the readonly box in the properties.

I have the button and the textbox. What I want to know is how, in the visual basic editor, do I get the subject box to change so that it can be editable when a user clicks the button?
 
Assuming the Subject TextBox is named txtSubject, the following should work:
Code:
txtSubject.Locked = False
or if you changed the Enabled property:
Code:
txtSubject.Enabled = True


Regards,
Mike
 
I have this code already written in ThisOutlookSession but when I click the button, nothing happens. Where do I put this code in the visual basic editor?

This is what I have written:

Code:
Private Sub btnPassword_Click()
    
    If txtPassword.Text = "Gehring" Then
        Subject.ReadOnly = False
        Subject.Enabled = True
    End If

End Sub

I just named the subject field, 'subject'. I also just created this procedure, it wasn't in the drop down list. How do I get the button (btnPassword) to get the subjectfield (subject) unlocked?

I've also used 'Subject.Locked = False' before but when I hit reply, outlook crashed and restarted. Also, what's the difference between ReadOnly, Locked and Enabled on the properties?
 
I assumed you were refering to MSForms TextBoxes on a Userform. Locked and Enabled are standard properties of those objects. I'm not well versed in Outlook. Where does the CommandButton "btnPassword" reside?


Mike
 
All of the things I want to do all reside on a custom mail message used to reply.

All I did was take the standard reply message, add a button (btnPassword) and a textbox (txtPassword) to it.

When I open Visual Basic Editor, there is no button click event to choose from. Any clues?
 
Sorry, I'm out of my depth on this one. I don't immediately see how to connect an event handler to the button or textbox objects placed on the mail reply form. I'll continue to poke around and post back if I come up with something.

Mike
 
Thanks a bunch for your help. I don't know why it isn't as simple as visual basic .net even though it's visual basic for applications. :/
 
Ok, this is what I've done so far. I opened the Script Editor and typed:

Code:
Dim btnPassword
Dim txtPassword
Dim Subject

Sub btnPassword_Click()
	
	Set btnPassword = Item.GetInspector.ModifiedFormPages.Item("Message").Controls("btnPassword")
	Set Subject = Item.GetInspector.ModifiedFormPages.Item("Message").Controls("Subject")
	If txtPassword = Hello Then
		Subject.ReadOnly = False
	Else
		Msgbox "Incorrect Password"
	End If

End Sub

The problem is that if I typed Hello, I still get the Msgbox Incorrect Password to appear. I even tried doing txtPassword = "Hello" and still got the same msgbox. If I took the password out, and just clicked the btnPassword, the subject is now editable, so I know that the btnPassword does affect the Subject.

Lastly, I thought that if I made the code:

Code:
Sub Subject_Exit()
     Subject.ReadOnly = True
End Sub

When the user tabbed out or just clicked elsewhere from the Subject, it would now be read only. But that is not the case. Any suggestions would be appreciated.
 
Replace this:
If txtPassword = Hello Then
By this:
If txtPassword = "Hello" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thx for the speedy reply, but like I mentioned in my post, I already tried txtPassword = "Hello" and I got the same incorrect message box.
 
Are you sure you entered "Hello" and not "hello" or vice versa ??

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Positive. Even thinking I could have some how mispelled it I copied/pasted it. Still to no avail... sigh
 
BTW, seems you omitted to instantiate the txtPassword control.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Not big on coding in Outlook but are you sure that the default property of "txtPassword" is actually the text ?? it is in excel (for a standadrd textbox) but thinking of other apps, Access has labels which have a CAPTION property....might be something similar here....

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Hah why yes I did. Works. Thanks. BTW, about the Subject_Exit() Sub... Like I mentioned, I basically want that when the user either tabs out of the subject line or just clicks elsewhere, the subject line becomes read only again. Here's the code again:

Code:
Sub Subject_Exit()
     Subject.ReadOnly = True
End Sub

I'm assuming I don't have to instantiate the Subject control again, either way I tried and it didn't work.

I thank you guys for your help.
 
As a follow up to that question. When I actually do send the email, and the user types in Hello to change the subject line, the problem is that the password is sent in the email as well. So, all I did was add one line of code so it looks like this now:

Code:
Dim btnPassword
Dim txtPassword
Dim Subject

Sub btnPassword_Click()
    
    Set btnPassword = Item.GetInspector.ModifiedFormPages.Item("Message").Controls("btnPassword")
    Set Subject = Item.GetInspector.ModifiedFormPages.Item("Message").Controls("Subject")
    If txtPassword = Hello Then
        Subject.ReadOnly = False
        txtPassword = ""
    Else
        Msgbox "Incorrect Password"
    End If

End Sub

I figured adding txtPassword = "" would delete everything in the textbox as soon as the user clicks btnPassword. For w/e reason it doesn't do anything. I've also tried txtPassword = NULL, with the same results.

I'm kind of just trying everything because, obviously, I'm not familiar with VBA. [rant] I wish it was similar to vb.net because I know that line of code would work. [/rant] :)
 
Again - I ask what the default property of txtPassword is - if it is not the TEXT property then you must reference it explicitly eg
txtPassword.TEXT = "Hello"

if txtPassword.TEXT = "Hello" then
txtPassword.TEXT = ""
else ...

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
The default property of txtPassword is text. Like you just pointed out txtpassword.text = "" would work in vb.net, but this outlook coding is set up much differently. Even though the default property is Text, if I wrote txtPassword.Text I would get an error message saying txtPassword.Text Object Required.
 
To reiterate PHV's question, where do you instantiate the txtPassword TexBox?? i.e., code similar to
Code:
Set btnPassword = Item.GetInspector.ModifiedFormPages.Item("Message").Controls("btnPassword")


Mike
 
My mistake, I did what PHV said and it worked, when I copied/pasted my code again onto this forum I must of overlooked it. But I did instantiate the txtPassword control and the code works. My problem, as I've posted, has to do with that Subjet_Exit() sub and the reverting back of txtPassword from Hello to "".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top