User Form Problems

K

Kenny

1. In my combobox1 click I need a stmnt to goto the next tab. The one I am
using also turns my num lock on and off?

2. I need to clear the controls in userform1 upon exit of the userform?

3. How do you BOLD a ref field for a bookmark?

4. How can I code hyphens to be placed in text placed in SSN spot and phone
number spot?

Thanks for the help!

Private Sub ComboBox1_Click()
SendKeys "{TAB}"
End Sub

Private Sub CommandButton1_Click()
Dim oBMs As Bookmarks
Dim oRng As Word.Range
Set oBMs = ActiveDocument.Bookmarks
Select Case ComboBox1.Text
Case "Army"
Set oRng = oBMs("Locator").Range
oRng.Text = "HRC - Indianapolis" _
& vbCr & "ATTN: AHRC-ERP" & vbCr & "8899 East 56th Street" _
& vbCr & "Indianapolis, IN 46249-5301"
oBMs.Add "Locator", oRng
Case "Navy"
Set oRng = oBMs("Locator").Range
oRng.Text = "World Wide Locator" _
& vbCr & "Bureau of Naval Personnel" & vbCr & "PERS 312F" _
& vbCr & "5720 Integrity Drive" & vbCr & "Millington, TN 38055-3120"
oBMs.Add "Locator", oRng
Case "Air Force"
Set oRng = oBMs("Locator").Range
oRng.Text = "HQ AFPC/DPDXIDL" _
& vbCr & "550 C. Street West, Suite 50" & vbCr & "Randolph AFB, TX
78150-4752"
oBMs.Add "Locator", oRng
Case "Marines"
Set oRng = oBMs("Locator").Range
oRng.Text = "Headquarters USMC" _
& vbCr & "Personnel Management Support Branch (MMSB-17)" _
& vbCr & "2008 Elliot Road" & vbCr & "Quantico, VA 22134-5030"
oBMs.Add "Locator", oRng
End Select
Set oRng = oBMs("CustomersName").Range
oRng.Text = Me.TextBox1.Text
oBMs.Add "CustomersName", oRng
Set oRng = oBMs("AccountNumber").Range
oRng.Text = Me.TextBox2.Text
oBMs.Add "AccountNumber", oRng
Set oRng = oBMs("SocialNumber").Range
oRng.Text = Me.TextBox3.Text
oBMs.Add "SocialNumber", oRng
Set oRng = oBMs("CSRName").Range
oRng.Text = Me.TextBox4.Text
oBMs.Add "CSRName", oRng
Set oRng = oBMs("CSRPhone").Range
oRng.Text = Me.TextBox5.Text
oBMs.Add "CSRPhone", oRng
Set oRng = oBMs("Amount").Range
pastdue = Format$(Me.TextBox6.Text, "Currency")
oRng.Text = pastdue
oBMs.Add "Amount", oRng
ActiveDocument.Fields.Update
UserForm1.Hide
End Sub

Private Sub UserForm_Initialize()
ComboBox1.AddItem "Army"
ComboBox1.AddItem "Navy"
ComboBox1.AddItem "Air Force"
ComboBox1.AddItem "Marines"
ComboBox1.Style = fmStyleDropDownList
ComboBox1.BoundColumn = 0
ComboBox1.ListIndex = 0
End Sub
 
G

Greg Maxey

1. Use the Change event with this code:

Me.TextBox1.SetFocus

2. Change UserForm1.Hide to Unload Me

3. Use a CharFormat switch. e.g., { REF "CustomersName" \*CharFormat }
and apply bold formatting to the "R" in "REF"

4. Use the Format Method. e.g., oRng.Text = Format(Me.TextBox3.Text,
"###-##-####")
and oRng.Text = Format(Me.TextBox5.Text, "(###) ###-####")

You might be interested in UserForm data validation. See:

http://gregmaxey.mvps.org/Validate_UserForm_TextEntry.htm


Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
 
K

Kenny

Thanks so much, works great!
How can I populate the formatting of the ssn or phone number back to the
textbox, after change?
 
G

Greg Maxey

Use the Exit event.
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox1.Text = Format(Me.TextBox1.Text, "###-##-####")
End Sub
 
K

Kenny

Thanks Greg!!!! Youy Rock!!!! Okay this is almost done I am learning so much.
One last question "I hope". On the document itself. How can you make the
Service Member: and Social Number: and Account Number: right justify so the
colons are line up. I tried to create a tab stop and right justify off of it.
It does not transfer it from the template to the new document? Is this
possible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top