SetFocus On TextBox As First Control In A Frame

May 9, 2005

In Excel 2000 there seems to be a problem with setting the focus in a UserForm TextBox if the SetFocus method is applied in the same submodule as the UserForm.Show method. Microsoft's circumvention for this is to put the SetFocus command in the form's Activate event submodule.

This seems to work OK except when the TextBox you are applying the SetFocus to is the first control inside a frame. It works if the TextBox is not the first control, and it can be circumvented by first setting the focus on a subsequent control then switching the focus to the intended control.

However, the circumvention is not that useful if there is only one TextBox control in a frame or, as in my current project, if you try to create a generic piece of code to validate controls from multiple forms and set the focus from within the generic code.

Does anyone know of a way over overcoming this problem and being able to directly set the focus to the first TextBox inside a frame?

View 9 Replies


Control Events And SetFocus

Feb 3, 2006

I have been working for 8-1/2 hours to get the focus to move to a specified control on my user form if criteria are met in two other controls on the same user form. It's not responding as I expect. I think I know what is happening; I just don't know why.

Situation: I have a user form with the following relevant fields in this tab order - LMonthDay, tbMonthDay, SBMonthDay, LYear, tbYear, SBYear, LTime, and tbTime. I used the designations L, tb, and SB in my control names to represent label, text box, and spin button respectively.

Problem: Once the SBMonthDay control has the focus, if I press TAB without changing the control's value, it does not execute the Exit event statement the way I anticipated. I want the focus to move to the tbTime control when the tbMonthDay & tbYear controls are already properly populated. (They will already be populated for 99% of the entries in this case.)

Private Sub SBMonthDay_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Debug.Print "SBMonthDay_Exit Begin"
If ISLIKE(tbMonthDay.text, "####") _
And ISLIKE(tbYear.text, "####") Then
Else: tbYear.SetFocus
End If
Debug.Print "SBMonthDay_Exit End"
End Sub ...........................................

View 9 Replies View Related

Setfocus From Module To Userform Control

Jan 1, 2009

I have a project with many textboxes on different forms. On some of the textbox_exits on some of the forms, I call a standard module that checks what the user has input. If the user needs to change the input, a msgbox appears to inform the user the info needs to be changed.

I have tried to use ControlSource, Name etc., But I cannot seem to setfocus back onto which ever textbox the input needs to be changed. I think it has something to do wih the _exit event, but not sure.

View 4 Replies View Related

SetFocus On TextBox

May 9, 2009

I have the below to check for a numeric entry and when it's not, it deletes the entry, shows a Splash Form for a few seconds telling the user to enter Numeric, and then unloads.

The problem is, on the SetFocus part. I thought that it should put the cursor back into TextBox2 for another entry. It doesn't, in fact the cursor is nowhere to be seen. I have to grab the mouse and click in the TB2 to reenter a number.

Private Sub TextBox2_Change()
'//Check for numeric entry
If Not IsNumeric(TextBox2) Then
Me.TextBox2 = ""
'//Show SplashForm if not numeric
End If

End Sub

View 9 Replies View Related

TextBox.SetFocus Not Working

Jun 8, 2007

if i write the following function on a checkbox,

View 10 Replies View Related

Validating Textbox On Userform And SetFocus

Feb 24, 2013

I have two userforms. When the user chooses the choice "Other" in the userform frmTradeSickOther, another userform called frmOther will be called. At this point, the user will enter some required comments in a textbox (called txtOther) and click the "Add Comment" button. If the user does not enter anything, a prompt will inform the user to type something in the textbox.

My problems: Once the user clicks okay to the prompt, frmOther is called back. When it's called back, I want the cursor to blink in the textbox. Eventhough I have SetFocus on the textbox, it does not work. I don't know why.How do I prevent the user from just hitting enter (i.e., accepting blank lines as comments) and bypassing the commenting part. The code below accounts for hitting enter once (i.e., one blank line), but not multiple times. How do I do this?

Here is what I have when the user clicks on the "Other" choice in frmTradeSickOther:

Private Sub optOther_Click()
Unload Me
frmOther.txtOther.SetFocus 'This gets the cursor to blink in textOther when frmOther is called.
End Sub

Here is what I have when the user clicks the "Add Comment" button on frmOther:

Private Sub btnAddComment_Click()
On Error Resume Next
txtOther.Value = Trim(txtOther.Value) 'This is to make sure spaces aren't accepted as a comment.
If Me.txtOther = vbNullString Then
MsgBox "Please enter the necessary information.", vbInformation, "Required Field"
Me.txtOther.SetFocus 'Here is where I set focus on txtOther.
Exit Sub
End If

'Everything below is to add comments automatically to each cell when a value is changed.

Application.CommandBars("Cell").Controls("Delete Comment").Enabled = True
If Not ActiveCell.Comment Is Nothing Then
Application.CommandBars("Cell").Controls("Edit Comment").Enabled = True

[Code] .......

View 4 Replies View Related

TextBox Setfocus Unexpected Call

Jan 31, 2010

I've got a user form with 12 textbox, one for each month a total textbox number 13 and a 14th text box (TB28) to enter $'s in.

AfterUpdate in each textbox 1-12 posts its value to a worksheet all values are summed in a =sum range which in turn populates textbox 13. When TB13.text = 100.00 it sucessfully calls a number of routines but what I can't get it to do is set focus on TB28.

Private Sub TextBox13_Change()
If TextBox13.Text = "100.00" Then
With FormPhasedAmt.TextBox28
.SelStart = 0
.SelLength = Len(TextBox28.Text)
End With
End If
End Sub

It returns a Run time error Unexpected call to method or property access highlighting .SetFocus. The rest of the code works OK. Is it because other textbox on the same user form have text highlighted because of the tab order?

View 9 Replies View Related

For Each Control In Frame/Page

Jan 30, 2009

For Each ctl in Frame1.Controls
'Do whatever
Next ctl
I also know you can limit the controls you diddle by doing:

For Each ctl in Frame1.Controls
If TypeName(ctl) = "TextBox" Then
'Do whatever
End If
Next ctl
But this gets absurd when it gets to the point I want it:

For Each ctl in Page1.Controls
If TypeName(ctl) = "Frame" Then
For Each ctl2 in ctl.Controls
If TypeName(ctl2) = "OptionButton" Then
' Do whatever
End If
Next ctl2
End If
Next ctl

Is there any way to simplify this? Can I define ctl as frame, for instance, and then it will only look for every frame object in Page1? Or is there some other trick I'm missing? Or am I just making userforms with too many wrappers?

View 9 Replies View Related

Caption Of All CommandButtons In UserForm Frame Control

Mar 29, 2008

I have frame on a userform with command buttons. Is it possible to loop thru and capture the command button captions in a textbox. I'm trying to put together keyboard on a userform, so the user can populate a textbox with letters or phrases.

View 6 Replies View Related

Hide & Show Scroll Bars For Frame Control

Nov 30, 2006

I have a form that is dynamically created at runtime. I have assigned the controls to a frame in VBA and also attached a horizontal scrollbar manually to that frame.

How can I control the scrollbar in VBA to appear, when columns of controls added to the frame exceeds 10. If not I want the scrollbar to be invisible?

Private Sub UserForm_Initialize()
Const cTextBoxHeight As Long = 16
Const cTextBoxWidth As Long = 40
Const cGap As Long = 10
Dim W As Integer
Dim a As Integer

View 9 Replies View Related

Access Control Properties Of Controls Within UserForm, MultiPage & Frame

Jan 30, 2009

I want to access the Properties of a number of controls in a running form, and these controls may or may not be contained in a Frame or a MultiPage.

In particular I want the Top and Left for these controls, which means I have to first find out if the control is contained in a Frame or MultiPage so I can get the reference for Top and Left. I'm ok with doing this for controls inside a Frame, but the MultiPage is eluding me. I get an error when I try to access these controls and it looks like they are actually owned by the individual Pages of the MultiPage.

how do I find out if a given control is contained in a given MultiPage?

Validate UserForm MultiPage and Frame Controls

View 3 Replies View Related

Update Textbox In Parent Frame

Dec 1, 2006

The code below works really great which Andy helped me with, but now I've put the textboxes that are changing in a frame. That is because I need to scroll the textboxes. That works in another form I've got, but for this form I've also got the textbox, TBSum601, which is updated from the sub UpdateTotal() (see below). BSum601 is placed on the form but not inside the frame. When I run the application it stops in Sub TxtGroup_Change() at the line: TxtGroup.Parent.UpdateTotal
I think it's because of that the textboxes for the TxtGroup now are in a frame instead of as before, on the form. don't know exactly what the "Parent" does, but I think it's something I have to do with the code there.

Originally Posted by Andy Pope
Class event
Private Sub TxtGroup_Change()
If Me.TxtGroup.Text = "" Then
Me.TxtGroup.Text = 0
End If
End Sub

Public Sub UpdateTotal()
Dim lngTotal As Long
Dim lngIndex As Long
For lngIndex = 1 To UBound(X) / 4 ..................

View 2 Replies View Related

Events On Textbox Within A Frame On Excel Sheet

Feb 22, 2013

I have placed a Frame Control on Excel Sheet and add Some Controls(TextBoxes) to it. What I want to Do is when I enter Value in TextBox1 and the Focus Got to TextBox2

Then Value from TextBox1 will place on Activesheet.cells(1,1)..

Please check the Attached File : FrameControls.xlsm

View 2 Replies View Related

Automatically Fit Text To The Size Of Textbox Frame

Aug 10, 2011

I'm trying to Automatically fit the text to the size of the TextBox frame using:


With obFinalNote.TextFrame2
strTxt = .TextRange
.WordWrap = msoTrue
.AutoSize = msoAutoSizeTextToFitShape
.TextRange = strTxt
End With

It appears ".AutoSize = msoAutoSizeTextToFitShape" only considers the width (I think) as the text is downsized but yet the text still extends beyond the the bottom of the frame. And never gets set to less than 11 point. Even when there's not enough text to reach the bottom of the frame the text is still set to 11pt leaving the frame half empty. Need to have text big as possible.

How to keep text in its entirety within the frame of the shape?

The quantity of text varies widely and the frame size cannot change. I've tried using Len() and dividing by a certain number and then based on that answer set the size with:


With obFinalNote.TextFrame.Characters.Font
.Name = "Arial"
.FontStyle = "Normal"
.Size = NoteFontSize
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

But this technique doesn't seem reliable as the number to divide the Len() by seems to depend on how "wraps" have occured.

View 5 Replies View Related

Access Textbox And Button Inside Form Of Frame Of Webpage?

Oct 10, 2013

I am writing a macro to automate the filling up some data from excel to company website. I have changed the website name in this post for data protection purpose. The excel will login for different clients by using the combination of username and password for respective clients and then some data are required to be inserted in a text box on a web page, I think the text box is on a form and form is within an iframe, within the web page. Once the data is inserted into text box, one button (Submit), which is also on the same form, is to be clicked.

On the click of a button, the updated data appears on another section, I could not make out if it is an form or frame, which is under the abovementioned form. Once we are happy with the way data appears on the web page, we have to click another button (Update), which is on the same section, to finally updating the data on website.

I wrote the following code to login to the website and then to navigate to the web page where I have to fill up the performance numbers in a text box.

The first problem is how to access the text box inside the form from VBA so that the macro can write a number in that text box and how to access the button to submit the data. The HTML code, which can be seen on click of F12, is attached below.

The second problem is how to access the Update button inside the other section, so that the data will be finally uploaded.

Sub LoginToCorpAccount()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")


View 2 Replies View Related

TextBox Control Being Cleared

Aug 18, 2006

I have a rather large userform with numerous textboxes and comboboxes. Data entered into the text and combo boxes is written to the next empty row of a sheet. As the data to be entered into the next row may not "all" vary from the last I would like to have the data I have last selected or entered remain in the textbox or comboboxes for the next. I attach an example for a better explaination.

View 6 Replies View Related

TextBox Control Lookup Code

Aug 17, 2006

i am trying to use a look up formula to populate a textbox on a userform. this is the code but obiously does not work

Private Sub TxtbName_Change()
End Sub

View 9 Replies View Related

Input TextBox Control To Corresponding Cell

Sep 27, 2006

When I select in my combo box I would like it to populate fields. That part is fine. When I try to input I want it to input in corresponding cell to the combo box selection i made. Problem is I can only get it to input in a certain cell not cell corresponding.

Option Explicit
Private Sub ComboBox1_Change()
Dim iRow As Integer
If Me.ComboBox1.Value = "" Then Exit Sub
iRow = WorksheetFunction.Match(Me.ComboBox1.Value, Range("People"), 0) + 1
Me.TextBox1.Value = Cells(iRow, 2)
Me.TextBox2.Value = Cells(iRow, 3)

End Sub

Private Sub CommandButton1_Click()
Unload Me.....................

View 6 Replies View Related

UserForm Control TextBox Or ComboBox

Jun 5, 2008

If this control is a TextBox, I would like to read the Text property,
and if it's a ComboBox, I would like to read the Value property.

Public Function readValue(c As Control) As String
If (TypeName(c) = "TextBox") Then
' convert the Control to TextBox then put readValue = c.Text
If (TypeName(c) = "ComboBox") Then
'convert the Control to ComboBox then put readValue = c.Value
End If
End If
End Function

View 9 Replies View Related

TextBox Control Passes Number As Text

Aug 21, 2006

I am trying to store some information in a cell from a UserForm. The two sets of information I have are:

InvoiceNumber(number with no decimals)
InvoiceAmount(currency with two decimal points)

The problem I get is when I use the following command to store the information, it stores the information as text rather then a number.

Worksheets(CustomerName).Range("C" & Position + 1).Value = InvoiceNumber
Worksheets(CustomerName).Range("E" & Position + 1).Value = InvoiceAmount

I tried using the NumberFormat option as below, but it doesnt fix the problem.

Worksheets(CustomerName).Range("E" & Position + 1).NumberFormat = "$#,##0.00"
Worksheets(CustomerName).Range("C" & Position + 1).NumberFormat = "0"

View 5 Replies View Related

Control Toolbox TextBox Moves When Printed

Aug 28, 2006

I am using a form textbox on a worksheet. I have the textbox positioned where I need it to be but when I print the worksheet the textbox moves out of position.

View 9 Replies View Related

Allow Control Toolbox Textbox Font Editing

Sep 6, 2006

I have an excel workbook where on several of the worksheets I have Control Toolbox Textboxes inserted into the sheet. The Textboxes are for when a user wants to type notes onto the worksheet.

My issue is that the Textboxes do not allow the user to edit the font because the VBA project is locked.

How can I allow users to edit the font in the Textbox without giving the VBA password away to the user?

View 10 Replies View Related

Calculate/Display Times Greater Than 24 Hours In TextBox Control

Oct 23, 2006

I have made a userform where I calculate how long time an operation takes. If the time fe.g. is 25 hours and 24 minutes then I get the result 1:24. I have attached my userform as it looks now. If you write 540 in the bar and 550 in volume and press "Beregn" then "Norm tid + 10%" will write 1:24 and not 25:24. Is it possible to have the Userform to write 25:24 or 1day and 1 hour and 24minutes?

View 2 Replies View Related

Pass Calendar Control Date To Selected TextBox On Another UserForm

May 9, 2008

I have a workbook that has multiple spreadsheets. Data is added to the spreadsheets using userforms for each spreadsheet. I have created a pop-up calendar to add dates and want to know if there is a way to add dates without having to create multiple calendars for each txt field on each userform. I would like it so that when I click on the calendar it would put the date into the text field it was launched from.

This is the code in the calendar which only puts the date into the field named Dat_Clsd.

Private Sub CMD_Close_Click() .....

View 5 Replies View Related

Excel 2007 :: Textbox Control Source Linked To Cell In Spreadsheet?

Oct 10, 2013

I have a userform with a textbox and would like the user to type inside the textbox which in turn send the text typed to a cell on my spread sheet say sheet 1 cell ref A1. I am writing the following into the control source Sheet1!A1 but the control source does not except this. I am using excel 2007 .

View 2 Replies View Related

Set Textbox Control Source To Hidden Worksheet NOT Active Worksheet?

May 6, 2014

I have created an excel worksheet that will provide budgeting and estimating tools for my project managers. All data used to be manual entry and took a good while to complete. I am trying to automate the process with VBA.

I created a UserForm called InfoVerify1. On that form I have TextBox 1 - 10. When the UF opens, the boxes display project information from my worksheet called "Basis of Estimate", also known as Sheet26.

The TextBox1 ControlSource is set to "E4". When I run the macro with Sheet26 active, the proper information fills in. However, when I am on the Start page or any other worksheet and I run the macro, it tries to fill in the text boxes with E4, etc, from the active sheet. I tried changing the ControlSource to "Sheet26,E4" or any combo thereof with only error messages.

how to get it to refer to a cell on a particular worksheet and hold to that worksheet no matter which sheet I am on at the time I run the Userform?

View 3 Replies View Related

Setfocus + Show A Page

Nov 7, 2008

Excel 2003. User form coding an If statement the "Else" FieldName.Setfocus. The User form has a MultiPage object in addition to the above (setfocus) in a particular field (NOT on the MultiPage object) I want it open to Page2 instead of what ever page it was last closed on. I tried this: MultiPage1.Page2.Enabled

View 2 Replies View Related

Using SetFocus To Any Other Object On Userform

Jan 11, 2010

I have been trying to setfocus to any other object on my userform with absolutely no luck at all?

In the code below I open a dialog box to import a text file (with CommandButton1), if no file is selected the user is prompted, this works fine. However it leaves focus to the textbox and the user would have to click on some other object and re-enter the textbox to open the dialog box again.

View 3 Replies View Related

Setfocus In Userform Not Working

Dec 29, 2009

I'm having some problems with SetFocus on a user form that I am using. Code is Below.

Dim Answer As Variant
With cboAccount
If .Value "" And .ListIndex = -1 Then
Answer = MsgBox(cboAccount.Value & " is not a registered account, would you like to add it?", vbYesNo)
If Answer = vbYes Then
Load frmNewAccount
frmNewAccount.txtAccountName.Value = frmEnterTransaction.cboAccount.Value
If Answer = vbNo Then
End If
End If
End If
End With
End Sub

basically the code asks if the if the answer placed in a cboAccount (combo box) is valid against the list designated to that combo box,

If the entry is not valid a message box appears asking if they would like to add the entry to the valid list if they do not want to do this they can click no and in which case I wan't the focus to be set back to the combo box however currently the setfocus command above does not does not work and the focus is set to the next text box.

View 9 Replies View Related

Setfocus To Combobox On Multipage

Apr 17, 2006

I have a userform with a multipage consisting of 4 tabs.

Each one has several combobox's and 1 commandbutton.

As you move through the form the commandbutton moves the data to my worksheet then moves you to the next page. When it reaches the last page it will return you to the first page then unload the form which is great.

The problem I am having is the cursor is not in any of the boxes on the first page. If I click on one of the other tabs then return to first page the first combobox has the focus. All the tab orders are correct. Can anyone point me in the right direction.

Private Sub cmdNext3_Click()
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If

View 9 Replies View Related

Copyrights 2005-15, All rights reserved