UserForm - Keep User In Textbox If They Made Format Input Error
Oct 27, 2012
I have a userfrom with a text box which is used to receive a telephone number from the user. The 'Event' code that checks the formatting of the telephone number is "tbCustTel_Exit". If my user enters a format other than what is acceptable for a tel number, they get an error message telling them to re-enter.
My problem is they still end up EXITING that text box they made a mistake in? How can I override them exiting the text box if they make a mistake - and keep them in the text box so they can try and re-enter the tel number again?
I having problem to determine the format value of dates that needs to be inserted in a Userform.
I have the following format in my userform for my Textbox:
When I select the calendar in my userform that is set as follows:
And select the first day of the month, it will always add the format as 05/01/2014 but if I select today’s date as example it will add it in the right format: 2014/05/26
I have included a sample to demonstrate the function of the calendar as I have declared it public as d in a module, therefore making the population of my userforms textbox easier to add information on dates.
If you add 2014/05/01 - 2014/05/26 and 2014/05/06 you will see where the system is having problem with the month and dates I guess the system confuses the two?
I'm learning 'on-the-job' to code VBA macros and about a week ago I asked a colleague to test (UK/Australian) date entry into a textbox on a userform. I wanted to ensure users can enter virtually any acceptable date format. About 10 minutes after sending the colleague the workbook, she advised that inputting 29 February and a year that is not a leap year had the effect of showing the textbox date in reverse and transferring that date to the workbook with the year indicated as "29" eg. 06-Feb-29.
Since then, I've spent a good deal of time seeking a correction to the code. I've tried scripts for 'If IsLeapYear' with the 'MonthLength = 29' etc, various other if statements and shuffling the original date order of my code. The unadulterated code is below. Does anyone have an answer (other than an Error Handler with a msgBox, informing the user that the date format is wrong)?
Private Sub txtMonth_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim dDate As Date dDate = DateSerial(Year(Calendar1), Month(Calendar1), Day(Calendar1)) dDate = txtMonth.Value txtMonth = Format(dDate, "dd-mmm-yy") On Error Goto EndMacro Exit Sub EndMacro: MsgBox "The date format you've entered is not a valid format!" txtMonth.SetFocus
1) Can a userform procedure be place in the midst a larger macro, so that it can get input from the user before running the rest of the macro? ie If the user leave the input field blank, the macro will exit will a msgbox.
2) I have a range(A1:A3) that i want my userform to display. This range is dynamic. The user will require to input the corresponding country next to it. how do i code the this? I will need to use a listboxes and textboxes right?
for example: userform shows city on the left, user will need to input the country on the right.
A1 - California (user input on the right) A2 - Shanghai (user input on the right) A3 - Mumbai (user input on the right)
what I want. It relies on an input box asking the user to enter a part code, which when found creates a duplicate copy. However, if the user enters a part that doesn't exist I get a run-time error. Can anybody point me in the right direction so when a user enters an incorrect part they get a message telling them it doesn't exist.
Private Sub SortTest_Click() Dim s As String Dim r As Excel. Range
Range("A2").Activate s = InputBox("Enter the number you wish to find") If StrPtr(s) = 0 Then MsgBox "You must enter an existing part number!" Else Set r = Cells.Find(What:=s, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False)
I have a userform with 16 Textboxes Named "Text1" through "Text16". What I am trying to do is apply code that if there is content in the textbox it generates a new row after row15 and inputs the text in cellA of that row. Ex. "Text1" = JOE "Text2" = TONY......Hit Commandbutton1 on userform. It inserts Row16 puts "JOE" in A16.....then sequentially it inserts Row17 puts "TONY" in A17.
I want to force my user to input a date in a userform. I have a normal Textbox and assumed i'd be able to set the properties to mean that imput had to be an integer and the format had to be "00/00/00" but I can't see how to do this.
I don't want the end user to do anything to TextBox2 (I've got it set to Enabled=False). I would like TextBox2 to populate in $$ format based on a formula : TextBox1 % x Range("Sales_Price")
I can get TextBox2 to populate correctly, but I can't get it to convert to $$ format. Everything I've come across uses the 'Exit' or 'AfterUpdate' event - but I don't think I can use these events since the User won't actually be doing anything to TextBox2.
A particular textbox in myuserform requires a displayed format of 000.000. I would like the user to enter a no less, and no more, than 6 digits. On tab, the textbox displays that value in the preferred format.
eg. enter 123456, TAB, results in textbox display of 123.456
I have tried ...
[Private Sub freq_AfterUpdate() freq = Format(freq, "000.000") End Sub But this results in 123456.000
while trying to limit the user's input to a userform textbox to no avail. For example one textbox on the form should only be numbers and I therefore want to restrict the user to typing in a two digit code like 02 or 72 (not for calculations). Another textbox I only want to allow the user to input 6 characters in the format letter, four numbers and a letter. If the user inputs the wrong stuff a message box pops up and the focus is reset
I have a textbox in an excel userform and want the display to be formatted. When "9.1" is entered "9.100" shows either before or after going to the next textbox on userform. The code below is not working.
Private Sub UserForm_Initialize() txtWaste = Format(Me.txtWaste, "00.000") End Sub
I have a calendar userform that enters a date into a userform textbox in the format mm/dd/yy.
I am in the UK, so default date format is dd/mm/yyyy but i need it as above - mm/dd/yy
So, when I get a MsgBox to repeat Textbox1.Value (the date from the calendar object, formatted mm/dd/yy) and repeat it in format dddd mmmm dd yyyy, it reads the value not as I want it, mm/dd/yy, but as the usual dd/mm/yyyy - so instead of reading 08/01/12 as Wednesday August 01 2012 it is giving me Sunday January 08 2012 - even though in the cells on the worksheet that are populated from the textbox, the date reads correctly, so 08/01/2012 is indeed 1st August 2012 not January 8th 2012...
So it's the MsgBOx function reading the textbox in the userform wrong, and formatting makes no difference...
Can I fix this without changing my regional settings? Is there a way to set the region in vba then unset when leaving the program? I don't want to have to change regional, and anyway, the program will be used by others who won't know / want to do that.
Is it possible to selectively format text in a textbox on a userform ie. to make some of the text bold, other parts underlined and other parts italic etc. The text which appears in my text box is entered automatically by a piece of code which extracts the contents of certain cells and arranges them in the text box as needed. I would now like to be able to display the text box with the text formatted so that its not just all in plain text.
I have two sheets. sheet2 is a lookup table. sheet1 is information sheet. i have created a userform where a user inputs data into 3 textboxes and clicks a button. i have the code for transferring the data from the textboxes into row after the last used row on sheet1, columns a,b,c. in columns d and e i have vlookup code that takes the value in column c and performs the lookup function to return values found in sheet2. this all works fine.
I am trying to display the vlookup results in a 4th textbox on my userform.
I have a userfrom with 2 textboxes used for entering dates. would like to either force the user to enter the date as xx/xx/xxxx or have a calendar feature where they can select a date. I checked my 'additional controls' in my toolbox but do not see a calendar option.
I have the following macro in my spreadsheet to extract specific data from closed workbooks in a folder. It works great but what I would like to do is make it so I can just open the spreadsheet and press a button I create that will extract the data from the folder that it lies in.
Currently I have this specific spreadsheet just sitting by itself and I manually work out the address of where my spreadsheets lie and add that address into the code and run the macro. I find it a little cumbersome and me not knowing a hell of a lot in VBA don't know what the command is to make it pull the data from the folder that it resides in. Once I do this then I can create a button and assign the macro to it. Can change the code to be able to extract the data from all of the workbooks in the folder that the macro enabled spreadsheet lies?
I have a user form that has a combo box "City" two text boxes one called "Flight" and the other "Date". What I'm trying to do is to prevent the user from saving the data input from the user form if any of those three fields is left blank. The code that I have so far checks all of the required fields, if any are left blank a message notifys which field(s) is left blank and return the focus back to that field. But the rest of code also fires.
What I really need is either to stop the code if any fields are blank and return the focus back to the blank field, the user completes the field(s) and clicks the save again, or better yet, pause the code until all the required fields are completed and then complete the save. (There is actually another 200+ lines of code in this sub, but I deleted it to keep the post a little shorter.)