Dirty on command? - vba

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.

Related

Control Source of a text boxes set to DCount function - Refresh issue

I'm setting the control source of text fields to return the value of a function (multiple fields with different filtering conditions). The form has a combo box with a list of years: when the user selects a specific year, the on change event triggers a refresh of all the fields.
My problem is the fields don't show any values unless after combo box's On Change events. I have to click on the form/fields before the values start showing up.
I tried to do form refresh & field's requery but doesn't work.
The text field's Control Source is set to:
=SummaryReport("Projects","G","1",[Forms]![frmSUMMARY_REPORT]![cmbYEARS])
What I'm trying to do is when the user selects a year from a drop down, the fields values are updated & displayed by the On Change event - currently they seem to be updated but are not showing unless I click on the screen and that's when values start showing up in each field.
The method to update calculated fields is Me.Recalc (or myForm.Recalc):
https://learn.microsoft.com/en-us/office/vba/api/access.form.recalc
Try this instead of .Refresh.
Also I think the better event to use is After Update instead of On Change for a combo box.

Adding multiple textboxes to a form in ms-access?

I would like to have a line on an Access user-form. Call it Item #1. I would like Item #1 to be a text box where the user can enter any type of information. So for example, say the user entered "Tutoring" and then next to this was an additional Textbox that allowed the user to enter the hours spent tutoring and the date in which the hours were logged.
What I would like is to have a button to allow the user to add a second line (or set of textboxes) when needed, or a third line, etc. Is this something that can be set up on the Access form? Does this need to be coded in VBA? Just looking for some tips to provide me some direction on the best approach.
"If the data should not be stored in a table, it' a bit more complicated. "
You would have to make the text boxes not visible when the form loads, and then make each text box visible on the After Update event of the previous box.

Use command button to open selected record on a form without filtering?

I have a continuous form which displays a small amount of data from each record in my table ProjectT (i.e. project name, status) and a command button in the footer which I would like to open the selected record in its expanded single form (where all of the relevant info is displayed).
At first I set this button up using Access's wizard, but realized that Access opens a selected record by filtering the data on the form. The problem with this is that once the expanded form is opened, I want a user to be able to move to other records without having to select to unfilter the results. If I change the button on my continuous form to simply open the expanded single form, is there code I can run to make the form open to the selected record without putting a filter on?
Initially I thought to set the expanded form's (named ProjectF) default value to Forms!ProjectListF!ProjectID (where ProjectListF is the continuous form and ProjectID is the autonumber primary key for ProjectT), but this was not successful, I think because there is more than one ProjectID displayed on ProjectListF.
Another thing to consider is that I have another button on my Main Menu form which opens the ProjectF form in data entry mode to prevent the user inadvertently changing/deleting an existing record when they are trying to add a new one; I have no idea if this might be important when trying to find a solution to my issue.
I'm open to any suggestion--I have an okay handle on SQL, and have delved into a little VBA but am completely self taught. Any ideas? Thanks!
You can open the detailed form with this command:
DoCmd.OpenForm "ProjectF", , , "[ProjectID] = " & Me!ProjectID.Value & ""

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.

stop enter from going new record access 2007 vba

I have a form (split form) and i want to prevent access from creating a new record when the user reaches the final field of form and hit the enter key. I already tried to change the Cycle property in the Other tab and didn't work
By split form i mean a form that has Split Form on Default View in the Format tab
On Access Form,
Form.AllowAdditions = False
Will forbide adding new record.
You can set this property in both the design view and at the running time.