Validate button must be clicked before closing workbook - vba

If user changes/writes into excel sheet then he must click the validate button.If he changes data and tries to save/close excel,pop up must be show to the user. Simply I want to check whether used clicks validate button before closing the workbook. If a single letter is changed by user, user needs to click on validate button. After clicking on validate button ,if user again changes any data ,then too user must get warning that validate before saving/closing.

I don't want to write out all the code for you but what you'll need to do is create an on-change worksheet(Or workbook if you'd prefer) process that sets a custom worksheet attribute or your preferred method of storing a value persisting between sessions. That process will run when anything in the worksheet changes and will be able to set the value of your value so that you know "there has been a change, I am now not validated"
Then you need to create a before save process that checks to see if that value is "not validated" or "validated" (false or true or what have you). You set that process to break the save event and present an error message when the value is "not validated" and allow it when it is "validated".
Then you create a validate button/whatever and a process that sets the value to "validated" (may want to check and only change when the value is not already "validated" but that's up to you).
Then you'll have a set of processes where when the sheet/book changes, the value becomes invalid and saving is prevented. When the validate button is selected, the validate process changes the value to validated and saving is allowed again.

Related

Dirty on command?

I have an Access 2010 application that has a form with a text box and a command button on it. Clicking the command button places a default value in the text box.
Question: When a user clicks the command button I can either:
Run an SQL update to save the new text box value in the data source that it is bound to plus set the me.textbox1.value to its new value, or
Run the same SQL update to save the new text box value in the data source that it is bound to plus do a form.requery?
Which is better? Would changing the bound value in the data source initiate a current event and an automatic requery?
Thanks in advance.
If you want to save the entry immediately, I would write the value to the text box, and do
Me.Dirty = False
to save the record in the bound form.
I see no point in doing this via SQL.
Would changing the bound value in the data source initiate a current event and an automatic requery?
No, that would actually be the worst method. The form wouldn't know about the changed data source, and once the user would start editing, he would get the "Write Conflict" message.
Your 1. would have the same problem.

Excel validation list allowing invalid inputs

I have a worksheet with several different validation lists using named ranges on a different sheet. I realized that the cells using the ranges with blanks in them still allow the user to type in whatever they want. If there's no blank in that defined range, then the normal Excel error message pops up. Anyone know why this happens?
Ex:
Both types of validation lists are the default settings with "Ignore blank", "In-cell dropdown", and the Error Alert checked.
Some of my lists have spaces in between them but I would still like to restrict users to selecting only the choices provided by the dropdown.
Update:
I tried unchecking the "Ignore Blanks", but one minor issue this causes is that now the user can't press "Backspace" to clear the cell. They have to actually select one of the blank rows in the drop down list.
I discovered another issue which may only be specific to my code (not the example):
-if the cell already has an option selected
-the user tries to delete the cell via "Backspace" and the Excel error message pops up
-if I click Retry and click on the drop down list again, I get 3 of these:
-the error is from the Worksheet_Change sub and occurs despite me having an error handler within it
You need to uncheck the option for Ignore blank in the data validation dialog box.
Then Excel will give an error message when the user tries to enter data even if there are empty cells in the named range used by the data validation.

Don't enter in VBA macro when editing

I have a drop down list column in an Excel worksheet to select a category. I have created a macro who replace the selected value by its ID after category selection (Worksheet_Change event).
Users have to fill the worksheet with ID but thank to this function, they just have to select a category in the drop down list and the ID replace the user choice.
It work well but I have a problem: if the user wants to write directly the ID in the cell, I have an error (Invalid value) and the macro is disabled.
How to do the difference in the Worksheet_Change between a change by the drop down list and a change by writing ? Or is there an other solution ?
Thank you !
If I understood correctly and you ARE using Data Validation:
Data Validation allows the user to optionally trigger an Error message if an incorrect value is entered (This error is the default setting). If you want to allow users to input information NOT in the list, turn off the error message by doing the following:
In the Data Validation dialog box, you will notice there are actually 3 tabs: Settings, Input Message, and Error Alert. Select the Error Alert tab, then UNCHECK Show Error Alert after invalid data is entered.
Does this resolve the problem?

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.