Hello everyone, I have a problem with the form when I close it, it asks me to save the changes every time. The code works well when filtering, if anyone has a better way to do this, (I think it's a bad idea, deleting the query every time I filter, I found the code on Google) I would appreciate it.
The code works well when filtering, if anyone has a better way to do this, (I think it's a bad idea, deleting the query every time I filter, I found the code on Google) I would appreciate it.
It needs the query because your CreateQry routine assigns the result as SourceObject for the subform. I think most Access developers would agree that it's better to just create a form that shows all the records of this SELECT statement:
SQL:
SELECT Tbltype.FldName,Tbltype.FldUni,Tbltype.Fldcost,Tbltype.Fldventa,Tbltype.fldflag as ACT,Tbltype.idfamilia As FAM
from Tbltype
Then, you will be able to assign it to the subform control. That way, your combobox can be used to trigger the Filter/FilterOn sequence of said form in the subform control.
But it's up to you to choose the right behavior.
EDIT:
If the form will be used for many other queries where that combo box will be used as filter, then your method would be a good alternative. However, I would still make an unbound form to assign it to the subform control, just to have the Form member of the subform control available for filtering with less code. Personal preference.
EDIT 2:
Besides, you have a hidden textbox that shows the current record in that subform control. Many people use that sort of setup to highlight the current record using a continuous form, but it can also be used for other things, like linking another subform (which is done a lot, but it's actually unnecesary most times). So, having an actual form and not a datasheet view could improve user experience. Perhaps, I'm just foreseeing the uses.
Make a form based on your query without any filters, put your unbound dropdown in the form's header, change the onchange event of the drop down to build a filter in vba and then apply it using Form.Filter. Lot less code.
If you set the save to no, be careful because if you are developing and you make a change to a form and then open it without saving, if you then close the form directly from form view, your changes will be silently lost.