LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default getting text out of TextBox into code

Using the code I have collected from various sources below I am trying to get the input from the userform textboxes into the various address fields to update Outlook "on the fly" but I can't seam to extract any input ? Can anyone suggest where I am going wrong please?


Sub AddNewContact1()
Dim TempForm 'As VBComponent
Dim Newtext As MSForms.TextBox
Dim NewCommandButton1 As MSForms.CommandButton
Dim NewCommandButton2 As MSForms.CommandButton
Dim NewCommandButton3 As MSForms.CommandButton
Dim NewCommandButton4 As MSForms.CommandButton
Dim NewCommandButton5 As MSForms.CommandButton
Dim NewCommandButton6 As MSForms.CommandButton
Dim NewCommandButton7 As MSForms.CommandButton
Dim First_Name As String
Dim TextLocation As Integer
Dim X As Integer, i As Integer, TopPos As Integer
Dim MaxWidth As Long
Dim WasVisible As Boolean
Dim olapp As Outlook.Application
Dim olCi As Outlook.ContactItem

Set olapp = New Outlook.Application
Set olCi = olapp.CreateItem(olContactItem)

' Hide VBE window to prevent screen flashing
Application.VBE.MainWindow.Visible = False

' Create the UserForm
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)
TempForm.Properties("Width") = 250
TempForm.Properties("Height") = 275

' Add the OptionButtons
TopPos = 4
MaxWidth = 0 'Stores width of widest OptionButton
For i = 1 To 10
Set Newtext = TempForm.Designer.Controls.Add("Forms.Textbox.1")
With Newtext
.Width = 230
.Height = 20
.Left = 8
.Top = TopPos
.Tag = i
.AutoSize = False
End With
TopPos = TopPos + 21
Next i

' Add the Manually Enter button
Set NewCommandButton1 = TempForm.Designer.Controls.Add("forms.CommandButto n.1")
With NewCommandButton1
.Caption = "Save Above to Contacts in Outlook"
.Height = 24
.Width = 200
.Left = 24
.Top = 222
.BackColor = &HC0C0FF
.Font.Bold = True
.WordWrap = True
End With

' Add event-hander subs for the CommandButtons
With TempForm.CodeModule
X = .CountOfLines
.InsertLines X + 1, "Sub CommandButton1_Click()"
.InsertLines X + 2, " "
.InsertLines X + 3, " "
.InsertLines X + 4, " Unload Me"
.InsertLines X + 5, " "
.InsertLines X + 6, " "
.InsertLines X + 7, "End Sub"
End With

' Show the form
VBA.UserForms.Add(TempForm.Name).Show

First_Name = UserForms(TempForm.Name).TextBox1.Value
MsgBox First_Name
With olCi
.FirstName = TempForm.TextBox1.Value
.LastName = TempForm.TextBox2.Text
.MobileTelephoneNumber = TempForm.TextBox3.Text
.Email1Address = TempForm.TextBox4.Text
.HomeAddressStreet = TempForm.TextBox5.Text
.HomeAddressCity = TempForm.TextBox6.Text
.HomeAddressState = TempForm.TextBox7.Text
.HomeAddressPostalCode = TempForm.TextBox8.Text
.SelectedMailingAddress = TempForm.TextBox9.Text
.Categories = "Business, Personal"
.Save
End With

Set olCi = Nothing
Set olapp = Nothing


' Delete the form
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=TempForm


End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate Text in Textbox to Ensure Text is a Valid Price Format Ryan H Excel Programming 1 November 12th 09 07:35 PM
Copy text then Past Text into TextBox not working RyanH Excel Programming 4 March 19th 08 10:33 AM
Printing text from a textbox in a userform using vba code Zigball Excel Programming 4 November 2nd 06 03:34 PM
Highlight all Text in a Textbox when the textbox is selected RPIJG[_73_] Excel Programming 3 October 28th 05 08:28 PM
Need VBA code to enter text into a textbox !!!! Art Ferdinand Excel Discussion (Misc queries) 1 May 6th 05 01:47 PM


All times are GMT +1. The time now is 08:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"