PDA

View Full Version : ComboBox Question...



junglej815
12-28-2007, 02:52 PM
Hello all,

I have a couple ComboBox's ( i believe are ActiveX controls from the Control Toolbox in Word ).

What I would like to happen is someone will fill out the form that I have in Word and select their choice in the ComboBox's. When the form is all filled out they will email it back to me by clicking on a Command Button ( also ActiveX I believe from the Control Toolbox in Word ). When I recieve the email and open the document I don't want to be able to change the selection they made in the ComboBox's. Is this possible? I hope it's clear of what I am asking. The code I have for the ComboBoxes right now is this:

Private Sub Document_Open()
With Me.ComboBox1
.AddItem ""
.AddItem "Data1"
.AddItem "Data2"
.AddItem "Data3"
End With
With Me.ComboBox2
.AddItem ""
.AddItem "Data1"
.AddItem "Data2"
.AddItem "Data3"
End With
With Me.ComboBox3
.AddItem ""
.AddItem "Data1"
.AddItem "Data2"
.AddItem "Data3"
End With
End Sub

The CommandButton code for them to email it to me is this if needed:

Public Sub commandbutton1_click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "Whatever the subject is"
.Body = "" & vbCrLf & _
"" & vbCrLf & _
""
.To = "email@email.com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub

Any help will be greatly appreciated.

junglej815
12-28-2007, 03:03 PM
I should make it clear that it is in a Document, not a form or anything special. And I guess I want to disable the boxes from being changed after it is sent back to me

fumei
12-28-2007, 03:22 PM
"When I recieve the email and open the document I don't want to be able to change the selection they made in the ComboBox's. Is this possible?"

I don't understand. If YOU don't want to change it....then...don't. Is something forcing you to change it?

Could it possibly be done? Sure.Private Sub Document_Close()
ComboBox1.Enabled = False
ActiveDocument.Save
End SubWhen the document is opened again, the selected value will be there, and locked.

BTW: you can load your comboboxes better by using an array, rather than all those individual AddItem instructions:Private Sub Document_Open()
Dim ItemStuff()
Dim var
ItemStuff = Array("", "Data1", "Data2", "Data3")
For var = 0 To UBound(ItemStuff)
ComboBox1.AddItem ItemStuff(var)
ComboBox2.AddItem ItemStuff(var)
ComboBox3.AddItem ItemStuff(var)
Next
End Sub Also, you do not technically need the Me ( With Me.ComboBox1) when you are executing ActiveX control code in the ThisDocument module...which you are.

junglej815
12-28-2007, 03:29 PM
Hey Fumei,

Thanks for getting back to me. The whole thing with this document is its a Conference Room Request form where people will select which room, what style set up, and a network connection...in 3 different comboboxes. Someone will fill it out then send it back to me and 6 other people. We just want to make it so that none of my co-workers or myself would be able to accidently change their selection because currently when its sent to us we can change what was selected.

fumei
12-28-2007, 03:33 PM
Missed your last post. If YOU want to disable them, then do so. You won't be able to do it with your Document_Open event though. At least not without some wriggling. But it would not be hard. Just run:Sub LockEmUp_Version1()
ComboBox1.Enabled = False
ComboBox2.Enabled = False
ComboBox3.Enabled = False
End Sub
OR....
Sub LockEmUp_Version2()
Dim strValue As String
strValue = ComboBox1.Text
ComboBox1.Select
Selection.Delete
Selection.TypeText Text:=strValue
' etc.....
End SubThe second would actually remove the control, and replace it with the text value, as ordinary text.

junglej815
12-28-2007, 03:37 PM
So this would make it so that they are enabled for the person to email it to me and upon emailing they are disabled?

fumei
12-28-2007, 03:40 PM
Keep missing here.

An alternative is lock 'em on Document_Close. Or put it into your emailing routine. If the procedure LockEmUp is in a standard module, NOT ThisDocument, then you can' ...other stuff...
Set Doc = ActiveDocument
With Doc
LockEmUp
.Save
End With
' your other stuff

junglej815
12-28-2007, 03:46 PM
Thanks a lot! .... I'll give it a try and see how things go.

junglej815
12-28-2007, 04:15 PM
Okay...the locking thing works...i tried this:

Private Sub Document_Close()

ComboBox1.Enabled = False
ActiveDocument.Save
End Sub


It worked...but it worked when I opened it from "my documents". I need to be able to open the file with the comboboxes enabled...send it to someone...they fill it out...send it to me...when I open the document from their email the comboboxes should be disabled....

Sorry, please bare with me and my inexperience.

fumei
12-30-2007, 02:52 AM
Not following.

What has "my documents" have to do with anything?

The document open event fills the comboboxes and they are enabled. Although - since I am not sur what is happening this may not be approrpriate - it may be a good idea to explcitly make them enabled in Document_Open.

No...forget that. The whole point is that they are enabled when the document is opened the FIRST time, but are disabled when the document is saved.

I am trying to understand what is happening. What exactly is NOT working????

junglej815
12-30-2007, 09:32 AM
Sorry it's confusing.

I have the document on my computer that I will email to you for example.
You will be able to fill out the form, make selections on the comboboxes.
You will email the document back to me.
When I recieve the document I am not able to alter your selections.

I was just curious if this is possible, it's not a big deal but would just be a nice thing so that none of "your" selections can't be changed accidently.

I tried one of the codes you provided the other day but it just permantly locked the combobox, i deleted the code and it was actually still locked, had to actually delete the combobox and put another one on the form.

fumei
12-30-2007, 07:50 PM
Sorry, but I am confused. If you mail me a document file, and your selection is locked....then...ummmmm...it is locked.

What on earth do you mean "permanently"? OF COURSE it is. That is exactly what you asked for.

"When I recieve the document I am not able to alter your selections."

What part of "not able to alter" allows for non-permanent locks? Not able to alter...except when I want to alter? That does not make sense.

Sorry, but I am not following this. I just wrote a document, with three comboboxes, just like yours. I used the code I posted so that Document_Close made them enabled = False. I just emailed it to myself.

I opened it.

"When I recieve the document I am not able to alter your selections."

That is precisely the situation. I can not alter what I had selected.

"I was just curious if this is possible"

Well...yes, it is possible. I just did it. It works exactly like that. The document I got emailed to me (by me it is true) has the selections I chose...and I can not alter them.

So tell me, what exactly is your problem? What is not working? I have asked this already.

"it just permantly locked the combobox, i deleted the code and it was actually still locked,"

And, ummmm, why would you think deleting the code would unlock it. It is locked (enabled = False) by code. Do you think - and apparently you do - that deleting the code actually does anything?

" had to actually delete the combobox and put another one on the form."

Oh no, you most certainly did not have to. The code locked them with:
Combobox1.Enabled = False

You unlock them with.....ta-da:Combobox1.Enabled = True

fumei
12-30-2007, 07:54 PM
Perhaps it would be best to start again and clearly articulate exactly what you want to happen. because I just did exactly what you have asked for.

A document with comboboxes.
I make selection on the comboboxes.
I email it.
The receiver (me in this case) gets the document.
The receiver opens the document.
The selected items are there, selected, and the receiver can not alter them.

If this is NOT what you want, then state what it is you really DO want.

If this IS what you want, then...well I don't know what else to say. I just literally tried it, and it does exactly what you asked for.

fumei
12-30-2007, 08:00 PM
Here, try it yourself.

Unzip the attached file.
Open ToMyself.doc.
Make selections.
Close the file.
Email it to yourself.
Open it.

You can see what you had selected...and you can not alter those selections.

Which is what you asked for.

fumei
12-30-2007, 08:02 PM
Oh, just for convenience sake, there is a wee procedure Sub EnableThem() in the ThisDocument module.

This is simply to unlock the comboboxes, if you wish to try it more than once. Rather than going through all that bother of deleting them and putting new ones in.....