Ms-Access - IF checkbox = true THEN - ms-access

How would i make it so that when 4 check boxs are all ticked (true) then the button may then be pressed to save the record.
The four checkbox s are called "chk1, chk2 chk3, chk4"
button is called "button"
i presume that it would something along the lines of "If Chk1, chk2, chk3, ck4 = True Then Button = visible?"
and then if the check boxes are not true then the button is not able to be pressed

You create a function that checks the checkboxes and sets the button state accordingly...
Function CheckMyButton()
Me.MyButton.Enabled = (Me.chk1 And Me.chk2 And Me.chk3 And Me.chk4)
' If you want to be more verbose, do
' (Me.chk1.Value=True And Me.chk2.Value=True And ...
End Function
... and call this function from the After Update event of all checkboxes.
Edit and probably in the Form_Current event too, if it's a bound form.
You can directly use
=CheckMyButton()
in the event property, no need for 4 event procedures.

Related

AS3: What is the best way to put button-behaviors ONLY on child_mcs of a container_mc

I have a container_mc, with lots of child_mcs inside. I want the child_mcs to have full button-like behaviors (click-able, cursor effects).
I am not interested in putting individual mouse listeners on every child.
... I would like to simply have one listener on the parent container, though the parent would effectively be inactive ... only the child_mcs.
Delfine the common behaviour of the buttons in a class and associate that class with the button symbol in the library.
You could listen to click events on the container with the useCapture flag set to true (addEventListener's third argument) - the listener would be invoked every time any container's child (including grandchildren and so on) is clicked. Then you could check which button was clicked for example by examining its name property.
Let's assume you have something like this:
var container_mc:Sprite = new Sprite();
addChild(container_mc);
container_mc.addChild(button1);
container_mc.addChild(button2);
//and so forth with all your buttons
To do what you ask, you would do the following:
//add a click listener to the container
container_mc.addEventListener(MouseEvent.CLICK,click);
//make the buttonMode true on the container, so you get the button hand cursor
container_mc.buttonMode = true;
function click(e:Event):void {
//e.target is a reference to what was clicked (see caveat after code sample)
//if all the children of container_mc are of the same custom class,
//you could now call a click handler on that item
MyButtonClass(e.target).myClickHandler(e);
//or you could use a switch statement
switch(e.target){
case button1:
//button 1 was clicked, do something with it
break;
case button2:
//button 2 was clicked, do something with it
break;
}
}
The only caveat here, is an event's target could be any child down line of container. So if button1 had some children and those children had children, the object referenced in e.target could be any of them (which ever was clicked). If you have child object inside your button, then the easiest way to make sure your target is always the button, is do the following:
button1.mouseChildren = false;
That will ensure any mouse events dispatched by the button, will have button1 as the target and not any of it's children.
please ignore the downvote ... if your problem is the same as mine,
then this solution works
//-- pseudo code --\\
*for the container:*
container.addEventListener( MouseEvent.MOUSE_DOWN , callback_function ) ;
container.buttonMode ...... false
container.mouseEnabled .... false
container.mouseChildren ... true
*for each child:*
child.buttonMode ...... true
child.mouseEnabled .... true
child.mouseChildren ... false

Removing an EventListener from an object decided via an Array

I am making a simple calculator for an assignment in my IT-Class. It has 3 textboxes where the user can add his numbers, and the boxes start with a "0" inside of them, to show that the user is supposed to write numbers here. What I wanna do, is have this zero go away as the user puts focus on the box.
Since I have 3 boxes, I wanted to make the EventListener call up a function that removes the text and the Eventlistener, instead of writing the same code 3 times.
Using an array containing the different textboxes I managed to call them up, and change the text as I wanted, but the EventListener isn't being removed, so the text the user writes in is being removed when they focus on the textbox again
///////////////////////////////////////////////////////////////////////////////////
//The Array containing all the TextFields
var textFieldArr:Array = new Array(txtNumber1,txtNumber2,txtNumber2)
function onFocus(i:int){
return function (evt:FocusEvent){
textFieldArr[i].text = "";
textFieldArr[i].removeEventListener(FocusEvent.FOCUS_IN, onFocus(i))
}
}
//Calls up the onFocus function and declares variable i
txtNumber1.addEventListener(FocusEvent.FOCUS_IN, onFocus(0));
txtNumber2.addEventListener(FocusEvent.FOCUS_IN, onFocus(1));
txtNumber3.addEventListener(FocusEvent.FOCUS_IN, onFocus(2));
///////////////////////////////////////////////////////////////////////////////
Your event listener isn't being removed, because when you call onFocus(i) within the removeEventListener param, you are being returned a new function, and not the function that was originally being triggered by the event. The other problem with your code is that 'i' does not exist in the listener function you have declared -- you need to use only the properties of evt to figure out which text field to target, and the correct event listener to remove.
The common/correct way to do this is to use a event-accepting function, and listen to each text field with it. You don't even need the array anymore unless you have some other use for it.
function onFocusIn(evt:FocusEvent):void{
trace("onFocusIn("+evt.target+")");
var focusedField:TextField = TextField(evt.target);
if(focusedField){
focusedField.text = "";
focusedField.removeEventListener(FocusEvent.FOCUS_IN, onFocusIn);
}
}
txtNumber1.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
txtNumber2.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
txtNumber3.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
Listener is not removed, because onFocus returns on each invocation new Function instance.
You might try use target property of FocusEvent class:
var textFieldArr:Array = new Array(txtNumber1,txtNumber2,txtNumber2)
function onFocus(evt:FocusEvent){
TextField(evt.target).text = "";
TextField(evt.target).removeEventListener(FocusEvent.FOCUS_IN, onFocus)
}
//Calls up the onFocus function and declares variable i
txtNumber1.addEventListener(FocusEvent.FOCUS_IN, onFocus);
txtNumber2.addEventListener(FocusEvent.FOCUS_IN, onFocus);
txtNumber3.addEventListener(FocusEvent.FOCUS_IN, onFocus);

right click menu in popup form

I'm new to this great forum.
I'm trying to do right click menu on listbox.
currently i'm trying to implement a right click menu which will show a simple messege box.
My problem is that the list box is on a pop up form which opened up maximized. Now when i'm right clicking on the list box i see the right click menu but when i'm clicking on one of the menu options, nothing happenning (it seems that it don't go to the function as it should). i've also putted breakpoints on the function but it never tips.
It's important to mention that if i'm setting the form popup option to no the right click menu works perfectly (when i'm clicking on one of the options i see its matching messege box).
I'm running the following vba code:
This is the mouse up event handler for my list box:
Private Sub Song_List_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Call the SetUpContextMenu function to ensure it is setup with most current context
' Note: This really only needs to be setup once for this example since nothing is
' changed contextually here, but it could be further expanded to accomplish this
SetUpContextMenu
' See if the right mouse button was clicked
If Button = acRightButton Then
'DoCmd.CancelEvent
CommandBars("MyListControlContextMenu").ShowPopup
End If
End Sub
setting up the "SetUpContextMenu" sub:
Public Sub SetUpContextMenu()
' Note: This requires a reference to Microsoft Office Object Library
Dim combo As CommandBarControl
' Since it may have been defined in the past, it should be deleted,
' or if it has not been defined in the past, the error should be ignored
On Error Resume Next
CommandBars("MyListControlContextMenu").Delete
On Error GoTo 0
' Make this menu a popup menu
With CommandBars.Add(Name:="MyListControlContextMenu", Position:=msoBarPopup)
' Provide the user the ability to input text using the msoControlEdit type
Set combo = .Controls.Add(Type:=msoControlEdit)
combo.Caption = "Lookup Text:" ' Add a label the user will see
combo.OnAction = "=getText()" ' Add the name of a function to call
' Provide the user the ability to click a menu option to execute a function
Set combo = .Controls.Add(Type:=msoControlButton)
combo.BeginGroup = True ' Add a line to separate above group
combo.Caption = "Lookup Details" ' Add label the user will see
combo.OnAction = "=LookupDetailsFunction()" ' Add the name of a function to call
' Provide the user the ability to click a menu option to execute a function
Set combo = .Controls.Add(Type:=msoControlButton)
combo.Caption = "Delete Record" ' Add a label the user will see
combo.OnAction = "=DeleteRecordFunction()" ' Add the name of the function to call"
combo.SetFocus
combo.Visible = True
End With
End Sub
setting up the all 3 function which shows different messege boxes on click:
Public Function getText() As String
getText = CommandBars("MyListControlContextMenu").Controls(" Lookup Text:").Text
' You could optionally do something with this text here,
' such as pass it into another function ...
MsgBox "You typed the following text into the menu: " & getText
End Function
Public Function LookupDetailsFunction() As String
LookupDetailsFunction = "Hello World!"
MsgBox LookupDetailsFunction, vbInformation, "Notice!"
End Function
Public Function DeleteRecordFunction()
' If Not IsNull(Forms!MyFormName.Controls("Song_List").Colu mn(0)) Then
MsgBox "Record Deleted"
' End If
End Function
Just set the Shortcut menu bar setting in the property sheet (in the other tab) to the name of your shortcut menu.
You at that point should not need ANY code to display/launch the context menu you created.

Toggle widget visibility with single button

The following code should write the inverse of true/false as found in the textbox back into the textbox when the button is clicked - but it doesn't work correctly. It will work correctly one way, but not the other (the one that works is whichever ClickHandler was defined last). I've tried using validateNotMatches too but no joy.
If I change the code so that the label's text is updated instead of the textbox's then that works fine.
I am aware of suggested workarounds such as using two buttons, but I just want to know if I'm doing something wrong or if this looks like a bug in GAS. Thanks.
function doGet(e)
{
var app = UiApp.createApplication();
var tb = app.createTextBox().setText('true');
var button = app.createButton('button');
var label = app.createLabel().setText('-');
button.addClickHandler(app.createClientHandler()
.validateMatches(tb, 'true')
//.forTargets(label).setText('false')
.forTargets(tb).setText('false')
);
button.addClickHandler(app.createClientHandler()
.validateMatches(tb, 'false')
//.forTargets(label).setText('true')
.forTargets(tb).setText('true')
);
return app.add(app.createHorizontalPanel().add(tb).add(button).add(label));
}
It's not a bug... both events fire. The validation happens on the current state of the widget, not on the state when the event was fired, so after you flip it to "false" the second handler validates and flips it back to "true".

Mouse "down/up" and "enter/leave" style for a button which is overlapped by transparent Flash object

I have a Flash object which dimension and position are as same as the HTML button. The button is under the flash object. I want when the Flash is clicked and hovered, the button has the styles as if it is clicked and hovered at the same time.
I am trying to call:
ExternalInterface.call("mouseEventHandle", elementId, eventName);
in Flash to pass event to JS.
And in JS (coffeescript):
window.mouseEventHandle = (elementId, eventName) ->
id = '#' + elementId
switch event
when "down" then console.log("down")
when "up" then console.log("up")
when "enter" then console.log("enter")
else console.log("leave") # leave
the function is responsible for styling the HTML button.
The question is how to style the button under in JS? Or is there other way to achieve the goal?
I finally use jquery buttons:
$("input[class!='hidden-input']").button()
so the handler function looks like:
window.mouseEventHandle = (id, event) ->
switch event
when "e"
$(id).addClass("ui-state-hover") # enter
return false
when "l"
$(id).removeClass("ui-state-hover ui-state-active") # leave
return false
when "d"
$(id).addClass("ui-state-active") # down
return false
else
$(id).removeClass("ui-state-active ui-state-hover") # up
return false
returning "false" allows browsers have quick reaction.