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
ADVERTISEMENT
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
View Related
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
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
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
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
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
Feb 20, 2014
Can Active-X control button macro be placed in a regular module, or does it always have to reside in the sheet module?
Or is the only way to accomplish this is to have the macro in the regular module being called from the button macro in the sheet module?
I somehow seem to remember a way to move/assign an Active-X ControlButton macro to a regular module, but maybe I'm wrong?
View 1 Replies
View Related
Jun 15, 2009
This is weird - if you delete a sheet that contained a control then
a. showing a modeless userform resluts in a userofrm that goes invisible at subroutine End
b. public variables lose their value
These things do not happen if the sheet did not contain a control. Attached is an example file - put the inputfile.xls in your default file location (or add a path in the code) then open the ProblemDemo.xls and run the main macro to see it fal - isthis another Excelbug I've found?
View 9 Replies
View Related
Dec 21, 2012
I have created an Excel Add-in to create the Text file. I want to create the text file through select sheet from userform.
View 9 Replies
View Related
Oct 24, 2009
I have been trying many different commands to run a module from a userform, but nothing is working. I'm sure it's possible, right?
Basically, I'm trying to run modules based on a selection made via a listbox.
View 9 Replies
View Related
May 3, 2012
I have several non-modal userforms in my App, some of them have date-fields that require manual entry typing of dd/mm/yy etc (No single userform has more than one date-box in it, this I think may be pivotally useful)
Now the Userform 'Calendar' that is built on the class of the same (cCalendar) name, has the write value line 'ActiveCell.value = theCal.value'
I'm looking to change this to refer to the correct userform.Textbox value, depending on which form is open.
I would imagine I could simply have a global string, whose value is set (or re-set) whenever a Userform is initialized (some sort of 'ActiveUF.value = Me.Name), where I get lost is referring to the components by name, so as to have a case statement by where I go:
Code:
Private Sub theCal_AfterUpdate()
Select Case ActiveUF
Case "AddForm"
application.vbe.components("AddForm").controls("AddFormDatePicker").value = theCal.value
Case "EditForm"
'.... etc
end select
end sub
better way of doing this (instead of passing around the userform name as a variable) - or proper syntax for referring to controls outside of the 'active' userform (but an open userform nonetheless)?
Every time I have to do this particular thing with userforms, I completely forget how, and the object browser always leads me on an infinite loop of Application.vbe.activevbproject.vbcomponents.vbe.active....
PS - there may be one slight complication to the process - one of the forms, has a 2-tab page in it, each page having similar (but named differently) fields. So I may need to be able to throw in 'Activepage' or whatnot
View 5 Replies
View Related
Feb 21, 2014
I got some codes defined as below and I want use a userform for and checking the process. If ı could use variable "i " in userform, my codes would work.
Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("E3:P36")
[Code] ......
View 2 Replies
View Related
Oct 25, 2012
I have a Sub() in a module that sends an email to address that it retrieves from a spreadsheet.
See portion of code below
HTML Code:
Do
vaRecipient = Application.InputBox( _
Prompt:="Please add the name of the recipient such as:" & vbCrLf _
& "excel@microsoft.com or just the Staff ID.", _
Title:="Recepient", Default:=Range("I" & vaRow).Value)
Loop While vaRecipient = ""
[Code] .......
This is basically showing 3 popup boxes one after the other to verify each address,
Is it possible to either have it show an input box with 3 fields or ( what I'm currently trying) is to show a Userform . I have tried Userform12.show but it isnt working.
View 2 Replies
View Related
Nov 2, 2006
if its possible to have the VBA object on one screen and the VBA code on another?
I can have the spreadsheet on one and the editor on another but carnt get it to work with the objects and code.
View 5 Replies
View Related
Jan 25, 2013
I have created a search all sheets function in VB in excel in a Module. All results are populated to a listbox in a userform.
What I want to do is, as soon as I select 1st result in the listbox, it must Jump to cell where the result was found.
If need be, I can mail you the excel sheet.
View 9 Replies
View Related
Jun 12, 2013
i have a userform where when i initialize i load my combo box with a range
I have a variable which = combo box value
Sub cmd click()
myval = cbo.value
unload me
End sub
How can i use or pass this variable to my standard module i.e
Sub test()
myevent = myval
end sub
View 6 Replies
View Related
Sep 9, 2013
I am trying to use some code similar to what i have used in one of my Modules in a Userform (The module calls this userform)
I have declared a few variables in the module:
Code:
Public LastRow As Long
Public TabLen() As Integer
Public AHUArray() As String
Public ArrayDim As Integer
and i want to try and use them in a userform (i call the userform through an bit of code that usures that the other subs that assign values to the variables have been used so there should be values in the variables??i think?)
i get to this line in my userform
Code:
TabPos = TabPos + TabLen(i)
this is the first line that requires a value to be in the array and it errors: Subscript out of range
I just want a few variable that are used in a module to be available in other modules and userforms.
EDIT:the (i) is decalred in this sub within the userform. A thought occurs, the sub in the userform is a private sub, might that effect it?Also, explain Sub vs Private Sub vs Public Sub?, im new to this! the sub that fils the arrays in the module is just Sub SubName_Click()
View 4 Replies
View Related
Aug 26, 2008
I have a splash screen (user form) which displays fo a number of seconds. The UserForm_Activate routine uses Application.OnTime to run the KillSplash subroutine, which is defined in Module1. Thing is, I would like to move the "KillSplash" routine to the UserForm module. What should be the full name of KillSplash I need to pass to OnTime? What "trick" do I use to make "KillSplash" visible to Application.OnTime?
View 9 Replies
View Related
Oct 16, 2006
I created in module custom toolbar with a button, see the
Option Explicit
Public ctrlGUI As CommandBarControl
Sub CreateToolbar()
Dim cb As CommandBar
On Error Resume Next
Application.CommandBars("Cust").Delete
On Error Goto 0
Set cb = Application.CommandBars.Add( Name:="Cust", temporary:=True)
With cb
.Visible = True
Set ctrlGUI = .Controls.Add(Type:=msoControlButton, temporary:=True)
With ctrlGUI
.FaceId = 3205
.Style = msoButtonIcon .............
View 5 Replies
View Related
Dec 15, 2006
I would like the users to be able to exit the whole module via double clicking the form. When the form is double clicked, the double click event appears and I am wondering how to put code into this procedure which exits the whole module.
View 3 Replies
View Related
Dec 28, 2006
I have a macro that when it runs presents a form that gives the user an option to skip the calculations or continue. If they click Skip then it continues the 'Next CE' . My problem is I can't get the Boolean value to pass from the form to the macro. Here is what I have
The main macro
Sub Dividend_MF()
For Each sh In ActiveWorkbook.Worksheets( Array("G&I", "Growth"))
For Each ce In sh. Range("a5:a" & sh.Range("a65536").End(xlUp).Row)
If Not IsEmpty(ce) And Not (IsError(ce.Offset(0, 56))) Then
If ce.Offset(0, 56) = "X" Then
View 9 Replies
View Related
Jan 9, 2007
I located combobox on userfom and don't see it in the module.
View 7 Replies
View Related
Jan 7, 2010
Can I place userform event handling within the code module where the rest of my program resides or does it have to go in the code module that is attached to the userform?
View 3 Replies
View Related
Mar 28, 2008
I am trying to pass a string array into a form. I have added a member string array to the form, and a property to "Let" the array in the the member array.
Private sFormString() As String
Property Let FormString(value() As String)
sFormString = value
End Property
I can pass a string in using a procedure:
Sub StringArrayTest1()
Dim TestString() As String
Dim frmString As FString
but I cannot "modulate" the code, or else I get an internal error (error 51). I.e. this code doesn't work:
Sub StringArrayTest2Mod(TestString() As String, frmString As FString)
frmString.FormString = TestString
End Sub
Sub StringArrayTest2()
Dim TestString() As String
Dim frmString As FString
Set frmString = New FString
Redim TestString(1 To 2)
TestString(1) = "Cat"
TestString(2) = "Dog"
Call StringArrayTest2Mod(TestString, frmString)
End Sub
Does anyone know why this happens? Obviously, in the example code its not an issue, but the application I'm using this for is more complex, and some modulation here would be good.
View 9 Replies
View Related
Feb 13, 2013
I am using Excel 2010 and late binding to generate reports. The sheets are blank and unused. I have the UserForm being opened on Workbook_Open and the actual VBA for doing the work in a separate macro in the workbook. All the posts I have found are dealing with accessing cells from the UserForm and I haven't found any dealing with connecting a macro to the UserForm output.
My question is this: I want to return from the UserForm the flags of which reports to run to the (unopened) macro containing the code to do so. How do I open the macro and pass the variables to it?
The UserForm is creatively called "SelectionForm" and the macro is called "DailyFTP" with a Main sub as the entry. I know I can use the code under to capture the radio button and checkbox choices. I have other variables like the names of files set as global variables in the DailyFTP macro. The macro doesn't exist until SelectionForm opens it, so they must be set after the macro is in memory.
View 6 Replies
View Related
Jul 16, 2014
I've a worksheet, which has formulas, links, combo list box and format control.
I've made a user form to enter the data, so that the particular cells in the worksheet is filled and the remaining cells are calculated as per the formula.The format control (combo box) has list of range.
Is it possible to bring this format control (combo box) on the user form, so that without going to the sheet, I Can control the sheet by selecting the combo box values.
View 7 Replies
View Related
Dec 17, 2008
I have created a simpel userform that shows sales total and it is activated [.show function] whenever an entry is made in the order column. All of this works fine.
The only problem I have is that the curser jumps in to the text box and doesn't return to the order column where next entry needs to be made.
How do you move the curser out of the userform, back to the activesheet?
Ideally it should move to the next cell for the user to make entry.
I am attaching my sample file here. It has some odd things that I was just playing around with as learning experience. But the main question is how to control the curser.
View 8 Replies
View Related
Jan 13, 2014
I have a userform with multiple images
I would like to set all images to visible = false when images are dynamically named.
E.g. image names:
Image73om3
Image4y45h
Image12AB2
Is there a way to say
Code:
With all images
visible = false
End With
or
Code:
image*.visible = false
View 5 Replies
View Related
Apr 3, 2008
I've got the bare bones of a toolbox control on my userform but I can seem to find anyway to refer to the buttons and control them (I’ve tried using the properties page but it doesn't seem to give me the options I need). I want to be able to add a macro and a picture to the buttons, is this possible?
Eg.
With Userform1.Toolbar1.button("x")
.image/picture/faceid = “x”
.action = "macro1"
end with
I've looked for ages on the board but can only find threads on creating toolbars in the application, not on userforms.
View 9 Replies
View Related