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
tbTime.SetFocus
Else: tbYear.SetFocus
End If
Debug.Print "SBMonthDay_Exit End"
End Sub ...........................................

View 9 Replies


ADVERTISEMENT

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 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 View Related

Control Order Of Class Object Events

Aug 19, 2008

Split from Determine Order Of Event Procedures

I realise that there's no set order for different types of event, because, as you say, it basically depends on what the user does. But what I'd like to control is what order like events fire in.

So let's say that object_1 handles the aplApp_WorkbookNewSheet event (an application-wide event).

Let's say that object_2 is an object of the same type as object_1, and therefore also handles the aplApp_WorkbookNewSheet event.

The objects are entirely independent; they know nothing about each other. However, I would like to be able to control whether the aplApp_WorkbookNewSheet event is fired first in object_1 or first in object_2 when the user triggers this event by adding a new worksheet somewhere.

View 4 Replies View Related

Enter & Exit Events In Control Classes

May 11, 2006

A lot of people seem to have been having troubles with the fact that if you try to use controls in a class with the "withevents" keyword, some events (like Enter & Exit) are not included in the tracked events. I have been having some troubles with this myself & have not yet seen any particularly satisfying workarounds to this problem.

So here is an idea I just had, I have not made any attempt yet to implement it & so have no idea how complicated doing so would be, but I thought I would just put it out here & get some feedback on the idea before I spend any real time working on it.

The idea is to create a blank, transparent label that covers the entire form, monitor the Click event of this label, & pass it back to the normal controls on the form as necessary. Does this sound doable, or do you all think it would be merely an exercise in futility? If anyone has any better suggestions for how to work around this lack of events,

View 4 Replies View Related

Disable Or Stop ActiveX Control Events Firing

Sep 8, 2006

I've several check boxes on a worksheet. Some of the check boxes control the values of other through the _click event. However, when I try to change the value the event attached to the control in questions fires.

application.enableevents = False

would prevent events being fire from within the macro but this only seems to work when I step through the code.

I understand that I could set a global variable to do this and will probably go down this route anyway - but I am interested to know how/when I should be using the EnableEvent method (as I am sure this should be the way that I use it)

View 9 Replies View Related

Excel2010 :: Userform Control Events For Controls Added During Runtime

Nov 20, 2013

I am using table driven forms controls on userforms. E.g.:

Excel 2010ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG1UI NameMultiPage ParentPage
ParentControlNameTopLeftHeightWidthCaptionTagControlTipTextSpecialEffectWordWrap
MultiLineBorderStyleBorderColorBackColorBackStyleForeColorColumnCountColumnWidthsListStyle

[Code] .....

I use the following (work in progress) function to add the controls to the userform (usually added to page or frame).

Code:
Public Function AddControls(ByVal objTarget As Object, ByVal strUiName As String)
Dim rngControls As Excel.Range, rngProperties As Excel.Range
Dim rngControl As Excel.Range, rngProperty As Excel.Range
Dim objControl As Object

With shtFormUI
Set rngControls = .Range("D2:D" & .Range("D" & .Rows.Count).End(xlUp).Row)

[Code] .....

Now I need a means of trapping the controls events. I thought I could use a class, e.g.:
cFormEvents

Code:
Option Explicit

Public WithEvents lblLabel As MSForms.Label
Public WithEvents tbxTextBox As MSForms.TextBox
Public WithEvents cbxComboBox As MSForms.ComboBox
Public WithEvents lbxListBox As MSForms.ListBox
Public WithEvents cbtCommandButton As MSForms.CommandButton

Private Sub lblLabel_Click()

[Code] .....

It seems I cannot reference the controls because I they are added at runtime. For the given example, I want to run whatever procedure name appears for lblPrimaryContact in column AC (click event). So in my userform module I instantiate the class, but I get an error when I try and reference the control:

Code:
Set m_clsFormEvents.lblLabel = Me.lblPrimaryContact
Error is "method or data member not found".

Any alternative method to grab the click event for the control added at runtime?

View 9 Replies View Related

UserForm Textboxes Triggering Events - Even After Events Have Been Disabled?

Oct 20, 2012

I have a UserForm with a Text Box, I populate that Text Box with a number (say 5) and then the following code runs:

Code:
Private Sub tbOverrideMokWh_Change()
Application.EnableEvents = False: Application.ScreenUpdating = False
With tbOverrideMokWh

[Code]....

After the Sub is run 1 time, it runs again. Why? I've disabled Events?

View 6 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
SplashForm.Show
Me.TextBox2.SetFocus
End If

End Sub

View 9 Replies View Related

Could Two Change Events (Conditions) Be Possible With Worksheet Change Events

Dec 13, 2012

I am aware that I can use single changing events in worksheet change events. For instance, if column 1, or A is changed, do something. This is only a single If statement, i.e. either the condition is true, or not. What I am not sure is if I can use two changing events, i.e. two conditions. For e.g. I would like if Column A value is X and Column B is "Active", action it, but only if two conditions are true.

For.e,g. The below syntax does not work. If it is only column A, it does work, but I want both A and B to be true, then copy and paste the target does not anything.

VB:
If Target.Column = 1 Then
If Target.Column = 2 Then
If Not Intersect(Target, Range("A2:A" & Rows.Count)) Is Nothing Then
If Not Intersect(Target, Range("B2:B" & Rows.Count)) Is Nothing Then
If Target.Value = "X" And Target.Value = "Active" Then

View 4 Replies View Related

TextBox.SetFocus Not Working

Jun 8, 2007

if i write the following function on a checkbox,

View 10 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
frmNewAccount.Show
If Answer = vbNo Then
cboAccount.SetFocus
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()
ActiveWorkbook.Sheets("CarDetails").Activate
Range("A1").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If

View 9 Replies View Related

Exit Event Running Twice Due To SetFocus

Feb 15, 2013

I am using a Textbox1_Exit event that (if certain values are true) sets the focus to different Textbox. However, when I invoke the Textbox3.SetFocus, it redoes all the code in the Textbox1_Exit event since it's technically leaving now.

How do I stop this from happening and ensure that the Exit event happens once? OR How do I properly SetFocus inside an Exit event?

View 8 Replies View Related

Setfocus (point To A Cell In A Spreadsheet)

Nov 25, 2008

I would like point to a cell in a spreadsheet, click a Command Button and copy the content of this cell to another cell, say D30.

View 2 Replies View Related

Event Keypress, Tab Or Keydown And Setfocus

Aug 26, 2009

How to setfocus on a cell, when user press enter, key up, or tab ?
examp. :

i want setfocus to cell A5, when i press enter or key up on cell A2.

View 2 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:

Code:
Private Sub optOther_Click()
Unload Me
frmOther.Show
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:

Code:
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
Me.Hide
MsgBox "Please enter the necessary information.", vbInformation, "Required Field"
Me.Show
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
Range(curCell).ClearComments

[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)
.SetFocus
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

SetFocus On Multi Page UserForm

Jun 18, 2006

I've got a userform with multiple pages, and in my userform initialize sub I set the focus to "combobox1" on "page1". When a user is on page2 of the form and clicks my "ClearData" button, which calls the initialize event, I get a run time error 2110 - "Can't move focus... etc" I would like users to have the ability to clear the form and start over no matter what page they are on.

View 8 Replies View Related

Avoid Hard Coding Control Name Inside Control Event Procedure?

Mar 4, 2014

Is there any way in VBA to refer to a control in its own event procedure without referring to it by name/hard-coding?

It might be clearer to explain by a dummy code example:

[Code] ......

I'm seeking what I would need to replace Line1 with.

View 11 Replies View Related

Select Next Control / Cell On Worksheet After Enter In Control

Jan 9, 2008

Within the ComboBox properties, is there anyway to control after "enter" his hit, you move to the right instead of down (similar to the edit under Tools/Options)?

View 9 Replies View Related

Drag From Treeview Control To Spreadsheet Control

Jan 12, 2007

I have created a userform within VBA which has a TreeView Control and a Spreadsheet control on it.

I have populated the TreeView control with data and what I want to be able to do is to drag the nodes off the TreeView control to the spreadsheet control.

I can drag onto a normal worksheet but not onto the spreadsheet control (the no drop mouse pointer keeps showing).

View 4 Replies View Related

Determine Active Control On Multipage Control

Oct 4, 2007

How do I determine which control the user is currently modifying on a multipage form (either changing, enterying or exiting the specific control). when I use "userform1.activecontrol" i get "multipage1" as the control name but I need the actual control on the specific active multipage. (also the .TABINDEX is for the multipage regardless of the on-page control) I use a generic data-field change SUBroutine so need the control name (and the TABINDEX) to provide my SELECT CASE. (so every fieldname_CHANGE calls the same SUB [with no parameters])

View 3 Replies View Related

Events

Jun 20, 2006

some times i choice (Initialize , active, open, click
Workbook_BeforeSave)
and so on

tell me as the differences and usage of these strings in order to improve our(my) programming skills.

View 3 Replies View Related

Two Events In A Workbook?

Oct 21, 2008

I am trying to write a code where user has to respond to input box option depending on yes or no selection. There are two types of responses to different questions. One needs to respond between 1 and 100 (if yes) and for some other questions needs between 1 and 4 (if yes). A "no" will enter zeo value. But it is not working. I am using two named ranges "VALIDCELLS" (for 1 to 100) and "FREQVALIDCELLSS" (for 1 to 4). Here is the code;

View 6 Replies View Related

Events Before Printing

Jan 30, 2009

I have early made a macro that will change some of the cells before printing and then changing back again to initional state after the print out.

http://www.excelforum.com/excel-misc...-printing.html

But now I have to do let people also print a copy a regular way, without the macro I made before. But if they go through the regular way iof printing I would like to insert at header in red color, to notify them that this is just a preview and not the way to print. And here we come to the problem ....

View 13 Replies View Related

Can't Create Events In VBA

Nov 14, 2013

why am I unable to create events on my worksheets? They were usually available to me when I selected "Worksheet" on the dropdown in vba.

When I open Excel, only "General" comes up in the drop down menu. What am I missing?

View 4 Replies View Related

Using Application Events With An Add-In

May 23, 2006

I've created an addin to reformat spreadsheets that I receive in a particular format. What I would like to do is enable events so that whenever a spreadsheet is opened the reformatting procedure is run (this also validates whether the spreadsheet is of the correct format).

I have created a class module with the following code (exactly as the Excel help):

Public WithEvents App As Application

Dim X As New EventClassModule

Sub InitializeApp()
Set X.App = Application
End Sub

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
SortE1Output 'This is my procedure that determines whether the
'spreadsheet is of the correct format and then reformats it
End Sub

"After you run the InitializeApp procedure, the App object in the class module points to the Microsoft Excel Application object, and the event procedures in the class module will run when the events occur."

When I try to make a call to the InitializeApp procedure in the auto_open procedure (in a different non-class module) I get a "compile error: sub or function not defined".

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved