Below code works perfect but the inputbox show’s text as "Wind" with auto selecting in the inputbox.
Is there any option to show without selecting... I mean the cursor should be last character of "Wind"
mycode...
Dim Prefex
Prefex = "Wind"
sNewComputerName = InputBox ("enter data here", "Computer Name", Prefex , 30,30)
If sNewComputerName = "" then
End If
To summarize comments:
InputBox is a very limited function, and doesn't have any possibility regarding the way it is selecting the default value.
so you need to press the right arrow before typing.
No other way around!
if you want nicer things, as #Rubik suggested, you can generate a proper InputBox with another language, you would be able to manage it. But that's a lot of work (rewrite your code!) for a minor disagreement!
What are you trying to do?
A user can take Wind out of the box and it will not be returned. If you want to make sure a user entered text the return value can be tested for "" or Wind.
if you want the " displayed
chr(34) & "Wind" & chr(34)
If you just want to prefix everything with Wind I would do that after the text was retuned
Related
I have an Access form with textboxes that contain some default text. The users are required to replace the text with words of their own, so I wrote a macro to confirm that (before proceeding to the next record) the text boxes no longer contain the default text. (It gives user a warning plus some other tasks, which is why I'm not using built-in Validation rules.)
The macro contains this sequence:
SetLocalVar
Name: booDetailDefault
Expression = [Forms]![frmChangeReq]![txtProblem].[Text]=[Forms]![frmChangeReq]![txtProblem].[DefaultValue]
The idea is if ...[Text] is the same as ...[DefaultValue], then booDetailDefault would be TRUE, and if not, FALSE.
However, what I do get is "Type Mismatch". I would think that Text and DefaultValue would be the same type.
Can you tell why I got this error?
Is there any way to display the Text and DefaultValue values so I can see why Access thinks they're different?
Is there a better way to see if the text boxes have been changed?
EDIT: The default text is set in the Property Sheet for the textbox. I've been running it manually, not tying it to an event yet, until I get it working.
I used Text instead of Value because that's what was available in the Macro Builder, but just in case I tried changing it to Value. It works, although I have to tell the expression to expect quotation marks around half of it:
[Forms]![frmChangeReq]![txtProblem].[DefaultValue]="""" & [Forms]![frmChangeReq]![txtProblem].[Value] & """"
For some reason, the solution those two questions (Q1, Q2) give on how to differentiate between "cancel" and "ok with an empty string" for an inputbox don't always work within a specific code of mine. I wasn't able to reproduce the problem so far so I'm looking for a different solution.
In my scenario, the inputbox pops up with a default value it got from somewhere else. So far I only needed to change this value through the inputbox so the simple check for if len(inputboxString) = 0 then to determine if cancel was pressed was working well. Now I got the case where I need to "clear" the existing default value. I'm trying to avoid using StrPtr for the reason I described above.
Here's the code that worked so far (as long as I don't need to use the inputbox to delete the value, since 'strInputBox = ""' is reserved for the cancel-event and I want to avoid using 'strPtr').
Dim strSomeStringFromSomewhere as String
strSomeStringFromSomewhere = someSubThatGetsTheStringValueFromSomeWhere
Dim strInputBox As String
strInputBox = InputBox(Prompt:="Edit/Delete Value", Title:="Title", Default:=strSomeStringFromSomewhere)
If strInputBox = "" then
'do nothing cause cancel was pressed
else
someSubThatWritesTheChangedStringBackToItsOrigin strInputBox
End If
The used value is usually some alphanumeric string e.g. d939d8ej3.
Any hints/ideas for a different user friendly approach would be welcome. (user meaning the person using the inputbox not the person who implements/maintains the code).
I figured out a nice work around, which should work in many other cases as well. In my case a single or multiple spaces are not a valid entries. And since I have to get rid of pre- and succeeding spaces anyway I just use trim(strInputBox) which will "clear" my value.
So the user just has to enter a space into the inputbox, which is good enough for prototypes.
On of our offices started their text data with an equals sign, which, when imported into the spreadsheet, gave the #NAME? error.
Now, I know I can change the cell format to text and then click in the formula bar, and excel recognizes the cell as text, but is there a way to do this through VBA?
EXAMPLE:
Cell display value: #NAME?
cell text =-Notice, ABC
Desired OUTPUT: Notice, ABC
now, normally, I'd do something like
sub convert_it()
if left(cells(1,1).value,2) ="=-" then cells(1,1).value = _
right(cells(1,1).value, len(cells(1,1).value) -2)
end sub
but that returns a type mismatch error.
Is there some way I can get the text in the cell without manually clicking?
I can click a few thousand times and then Excel recognizes it as text again, and not as an error, but I'd rather avoid that.
You can do this with VB, or just highlight the whole sheet, hit CTRL-H, type = in the Find and '= in the Replace, then click Replace All. This will make Excel stop thinking that these are formulas.
Instead of using .Value you have to use .Formula, since it's being interpreted as such here:
sub convert_it()
if left(cells(1,1).formula,2) ="=-" then cells(1,1).formula = _
right(cells(1,1).formula, len(cells(1,1).formula) -2)
end sub
Naturally you would place your code within a loop for the column. But I agree that it might be easier to just do a large find/replace.
I currently have a text box within a table that displays multiple stores based on user parameter input. The problem that I am experiencing that I would like to have a hanging indent that will force the store name to indent once it wraps to the next line (see screenshot).
Is this possible? I am aware that I could put the "Stores:" in it's own textbox, however this makes it difficult when it comes to lining up report items to prevent hidden/merged cells/columns during export to Excel.
The code that I am currently using in the text box is ="<b>" & Microsoft.VisualBasic.Interaction.iif(Parameters!StoreKey.Count > 1, "Stores: ", "Store: ") & "</b>" & Microsoft.VisualBasic.Strings.Join(Parameters!StoreKey.Label, ", ")
The Textbox property you're looking for is called HangingIndent. Try setting it to -10pt.
You could use a table, in the first column you put "Stores: ", in the second the string value, set the borders to none and finally play a little with the alignment (First column top-right alignment & Second column top-left alignment, its your choice) to make it look as if it was all in a single text box.
i would like to force the textbox to immediately change the text to UCASE as soon as the user moves away from the field. is this possible?
the important thing is that this text will be used in a SQL query to update a table.
In the after update event of the text box on the form, simply go:
If isnull(me.MyTextBox) = false then
Me.MyTextBox = ucase(Me.MyTextbos)
End if
You can also specify a input mask on the form.
">LLLLLLLLL"
The above ">" will force all chars as you type to upper case. The number of L is a any char mask. (and, you don't need the " around the input mask)
Solution from Albert don't work for me.
I use this method: put form in "design view", select the control, in the property sheet, in the format tab, in the format property insert the value ">" w/o quotes.