How do I highlight the content of a TextBox/RefEdit control and set focus simultaneously? - vba

I'd like to highlight the content of a TextBox/RefEdit control and set focus simultaneously when there is any invalid entry and after prompting a message box warning the error so that user knows where to fix the error. You can try Data>Analysis>DataAnalysis>Sampling and enter some invalid range/data, then you will be redirected to the invalid entry. The invalid entry is highlighted as well as with focus set (you can see a flickering cursor).
I tried to emulate this and I used,
aControl.SetFocus
aControlt.SelStart = 0
aControl.SelLength = Len(aControl.Text)
While the content inside the control is highlighted in blue, there's no flickering cursor as if I did not set focus of the control. How can I fix this? Or what's the best way to guide the user to the place where the invalid entry exists?

What if user inputs more than one invalid entries. How do you plan them all selected and setfocused at the same time.
There is no need to complicate things for you and for user. What you can do is create invisible labels with the right message you want to deliver to user, preferably in red color, and place them below each TextBox/RefEdit. Make them visible with Label1.Visible = Truewithin your conditional check.

Related

Lock OfficeRibonLabel size

I have an Excel VSTO plug-in which displays error messages in a RibbonLabel.
Changing the label text causes it to resize which causes its containing RibbonGroup to resize which moves the last group separator right and left with each message. This looks very annoying.
Is there a way to freeze Ribbon control size or, alternatively, any other way to display immediately visible error message which will not block the document itself (i.e. NOT message box)?
You could write the label to the status bar.
excelApp.StatusBar = String.Format("Processing line {0} on {1}.",rows,rowNum);

How to keep shape text but not show it?

My firm uses MS Azure Information Protection to attach privacy labels to documents.
When we send customer letters, the label shouldn't be visible. We select the Shape object the label is stored in, and set text fill to 'no fill', so the letter does not show the label. The but document still has the privacy setting embedded for internal retention.
Due to volumes this needs to be automated.
I cannot see anything in Shapes.TextFrame.TextRange that duplicates the 'no fill'.
You're looking for
ActiveDocument.Shapes(1).TextFrame.TextRange.Font.Fill.ForeColor
but I'm not aware of a "no fill" property for that. You could make the text the same color as it's background. But instead, try making the text hidden:
ActiveDocument.Shapes(1).TextFrame.TextRange.Font.Hidden = True

VB.NET Changing Colors for each line in a error message

Hi I created an error message that contains each value of whether or not is was a pass or fail. I would like each entry to change color based on Passed = green and pail = red.
Example:
Fare: Passed
Name: Passed
Date: Failed
Address: Failed
Age: Passed
This gets displayed in an output message box, currently
msgBox(errorMessage)
When this gets displayed I like the fails background to be red and the passed to have a
green background.
Currently I am still considered new to VB.Net I know how to do for mouse hovers and mouseleaves. I am assuming I need to make an event similar to those.
Thank you For your help.
You're not going to do that with MsgBox or MessageBox.Show, which MsgBox calls internally. You're going to have to create your own form and then either add one Label for each line, in which case you can set the ForeColor for each one, or else draw the text yourself using GDI+. If you do go the Label route, you'll probably want to use a TableLayoutPanel or FlowLayoutPanel to keep them aligned correctly.

Save a user popup selection in a custom Automator Action

Using Xcode 5.* for a cocoa-applescript automator action.
Interface is a a simple popup menu that gets populated using an outlet with:
tell thePopupMenu to removeAllItems()
tell thePopupMenu to addItemsWithTitles_(theList)
When the action is used in a workflow (a Service actually), I want the next time it is run and the action dialog shows up (I will have "Options:Show when run" selected), I want the popup menu to change the selection to the last one that was selected. Right now, the default first item shows, even though last time it was run, the user selected a different item in the popup menu.
My thought was that I need to capture a change in the popup menu with a Sent Action handler, and then set some type of default. I have a working handler:
on thePopupMenuSentAction_(sender)
set popupValue to (popupSelectedValue of my parameters()) as string
-- save this selection somewhere???
end
What's the right way to save this? Do I use User Defaults? My Bindings are currenly all tied through Parameter object/controller. If I should use User Defaults, can someone give example code for setting up User Defaults, and then how to get and set a new value using Cocoa-Applescript?
If I can get the name string of the menu item saved somewhere, I can get the string and then change the selection of the popup menu in the
on opened {}
-- set up the action interface
end
handler which gets called just before the action is displayed each time.
Thanks for any help,
Joe
I did mine a bit differently. I will assume you are referring to what XCode calls a "pop up button" (somewhat misleading). I did not use the parameters at all, although that is probably better for larger projects. Have a look at the code:
script Insert_Picture_into_Powerpoint_Slide_Show
property parent : class "AMBundleAction"
property menuChoices : {"Insert a Beginning", "Insert at End"}
property menuSelection : missing value
if (menuSelection as string) is "missing value"
set menuSelection to 0 as integer -- sets default value
end if
end script
I bound Content Values to File's Owner and under Model Key Path I put menuChoices.
Then you just bind the Selected Index to File's Owner and for the Model Key Path type menuSelection.
Defaults
On the initial run, if the user does not click anything, the menuSelection will be missing value. Because I couldn't find a way around this, I created a conditional which tests for this and sets it to the first choice by default (the one that is shown when you add the action).
When the user selections one of the menu choices, the choice is remembered on sequential runs.

How to change the Contents of a msg box

I have a form for creating a record, I also have a button on the top of the form for to return to a form called home. When the form is being viewed and half the information is put in and the home button is clicked an error pops up saying " you cannot add or change a record beacasue a related record is required in a table "Elements"." How do I Change what the content of the error message is ?
You can put checks in your button_click sub to circumvent -- check to make sure all fields are filled in, and if not, display your own message box followed by
Exit Sub
That will short circuit the rest of the method so you should not get the standard message.
Here is a resource on error-handling in VBA: http://allenbrowne.com/ser-23a.html
I'm not sure, however, if you can create a handler in VBA for standard program error messages.