Button to control both form and subform - ms-access

I have a form(Salefrm) and within that form there is a subform (Salefrm_subform).For now my Add command button will work only for the main form Salefrm , how can i make it work with Salefrm_subform as well.
Here is what happen when i click on Add .Do i need to have some code in Add to control the subform

Related

VBA get previous active control from parent form

I am usgin Access 2010 and I have a form that has a sub form, let's call it sform. I want to print the parent form's active control When I hit a button in sform. I tried
debug.print Me.parent.ActiveControl
But it prints the name of the sub form's container control, while I wanted the one that was active before it. Is that even possible?
Thanks
The active control on the parent form would be the sub form. To figure out what control had the focus before the sub form you may have to do something like the following:
Add a text box to the form called txtFieldThatHadLastFocus or whatever and hide it.
Then in the On Lost Focus event of all your controls on the parent form add:
Private Sub txtMyField_LostFocus()
txtFieldThatHadLastFocus.Value = "txtMyField"
End Sub
Then within the sub form you can figure out what control had focus before the sub form via:
Forms!ParentFromName!txtFieldThatHadLastFocus.value

MS Access cursor location in continuous form

I have a contunuous form where editing is disabled. If you want to edit an entry you have to select the line in a table and click the button "Edit".
The problem is when the form loads it's allways the first line of the table that is selected by default and if you click the "Edit" button a from will open with values from the first line of the main form.
What I want is the cursor to be set to nowhere when the form opens and if you click the "edit" button a message box would appear saying that no record is selected. How can this be done?
Put a header on the form, and put a textbox in the header that has the form's name or something. In the Load event of the form, set the focus to the textbox in the header. Something like:
Me!txtMyTextBox.SetFocus
That should get the focus off your continuous form.

MVC - override validation when one particular button is clicked

I have a table that lists items. I have a form tag that surrounds this table. In this table I have ADD buttons that adds new rows to the database. I have EDIT buttons that edits a row as well. The form posts to the same action on the controller.
Now I need to add a filter row on the first which means I need to add a Filter button to submit the form with the filter parameters. Since this is still inside the main form, I now have the following problem: When I click the Filter button, the inputs that are used for the ADD button are being validated before anything gets posted. How can I prevent the validation from occurring when the user clicks the Filter button?
Make sure the Filter button is of type "button" not "submit" and do filter using ajax
As i see it, the easy way would be to fire the submit via js with:
.submit();
The other way would be to disable validation on that form with this:
$('#form').validate({
onsubmit : false
});
or
$('#form').unbind('submit')
I have one suggestion. Name Add button inputs differently and add row using javascript/ajax. When posting, Add button inputs will not be validated because they have different names

use caption of pressed button from main form in query of other form

My problem is:
Main form has 9 command buttons and continuous subform. Click on some button open other form with text box for entering quantity and two command buttons. When click on the first button I want to use caption of pressed button from main form for query. How to get that button caption?
Thanks.
You have just clicked the button, you know the name of the control, so I do not quite see the problem, other than that it all sounds like quite a bad idea.
Private Sub cmdClickMe_Click()
Debug.Print Me.cmdClickMe.Caption
Debug.Print Screen.ActiveControl.Caption
End Sub

MS Access = referencing a control that is within a sub form

So I have a form, with a subform control that acts as a navigation scheme for my Main Form. Within the sub form, there is a sub form2 that actually contains the controls for data entry.
So the Main Form is almost just like a design shell around the sub2 within sub1 structure. So in subform1 there is 10 clickable buttons that open 10 different forms in the subform2 window. The subform2 contains the controls.....so here is my issue/question:
So if I have a click event on the subform2 where i am trying to open the next form (subform2 form) within the subform1 child control, which is within the Main Form, what is the vb syntax for handling this?
I am not sure if i am asking this correctly.
I tried:
Forms!SubForm1.MyChild.sourceobject = "NextSubForm2"
but this only works if the Main Form is not open....like if I only had the SubForm1 open.
One more thing, this is code behind the form of the SubForm2 (2 being the sub within the sub within the form).
The main form from a subform's point of view is:
Me.Parent
You can build on this:
Me.Parent.Subform1ControlName.Form.AControl
See also: http://www.mvps.org/access/forms/frm0031.htm
So:
Me.Parent.Subform1ControlName.SourceObject = "SomeForm"