Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
cvw cvw is offline
external usenet poster
 
Posts: 2
Default pass to textbox on a form and to excel worksheet

I have a calendar on a user form, along with 2 textboxes. The code works
thus far. The user must click in a textbox and click a date in the
calendar. I want the dates to also go to excel worksheet. Now it will if I
click on each textbox with the dates a second time. How can I get the dates
to go without that second click. My code is below: (NOTE: This is code I got
from the community site and revised for my needs)

Option Explicit
Dim LastTextBox As MSForms.TextBox
Private Sub TextBox1_Enter()
'Gives focus to textbox on userform
Set LastTextBox = Me.TextBox1
Worksheets("Part_Time_Payroll").Range("A2").Value =
Format(TextBox1.Text, "mm-dd-yyyy")

End Sub
Private Sub TextBox2_Enter()
'Gives focus to textbox on userform
Set LastTextBox = Me.TextBox2
Worksheets("Part_Time_Payroll").Range("B2").Value =
Format(TextBox2.Text, "mm-dd-yyyy")
End Sub

Private Sub Calendar1_Click()
'If a textbox is not selected, puts message on screen to select a textbox on
userform
If LastTextBox Is Nothing Then
MsgBox "Select a textbox first!"
Exit Sub
Else
'If a textbox is selected, puts date chosen in the selected textbox on
userform
LastTextBox.Value = Format(Calendar1.Value, "mmmm dd, yyyy")
End If
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub


Reply
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
Set Textbox on a Form to Deafault John Calder New Users to Excel 7 July 28th 09 01:39 AM
Text Size in Label or Textbox in Form Tony. D[_2_] Excel Discussion (Misc queries) 2 December 18th 08 03:09 PM
Textbox added to Form at runtime too small, can't control size andchange event won't trigger RCGUA Excel Worksheet Functions 2 December 10th 08 10:34 PM
end down option in a textbox of a form DTGvet Excel Discussion (Misc queries) 1 June 15th 06 02:01 PM
User Form in VB = TextBox Kel Excel Discussion (Misc queries) 1 August 11th 05 12:26 AM


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

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

About Us

"It's about Microsoft Excel"