Problem closing a form (1 Viewer)

Mario R. Perez

New member
Local time
Today, 08:06
Joined
May 14, 2020
Messages
15
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.
 

Attachments

  • Database1.accdb
    520 KB · Views: 19

GPGeorge

George Hepworth
Local time
Today, 05:06
Joined
Nov 25, 2004
Messages
2,060
This this in the click event of your command button.

Code:
Private Sub CmdSalir_Click()
    On Error Resume Next
   'DoCmd.Close
    DoCmd.Close Objecttype:=acForm, ObjectName:=Me.Name, Save:=acSaveNo
End Sub
 

Edgar_

Active member
Local time
Today, 07:06
Joined
Jul 8, 2023
Messages
438
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.
 
Last edited:

plog

Banishment Pending
Local time
Today, 07:06
Joined
May 11, 2011
Messages
11,676
It's this code:

Code:
Forms!frmMlFamilia!Childtype!FldName.ColumnWidth = 3660
Forms!frmMlFamilia!Childtype!FldUni.ColumnWidth = 1200
Forms!frmMlFamilia!Childtype!Fldcost.ColumnWidth = 1200
Forms!frmMlFamilia!Childtype!Fldventa.ColumnWidth = 1200
Forms!frmMlFamilia!Childtype!ACT.ColumnWidth = 800
Forms!frmMlFamilia!Childtype!FAM.ColumnWidth = 800

Why dynamically change the widths? Just set it at those. Of course the best way to do this is with Form.Filter:


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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:06
Joined
Feb 19, 2002
Messages
43,645
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.
 

Mario R. Perez

New member
Local time
Today, 08:06
Joined
May 14, 2020
Messages
15
This this in the click event of your command button.

Code:
Private Sub CmdSalir_Click()
    On Error Resume Next
   'DoCmd.Close
    DoCmd.Close Objecttype:=acForm, ObjectName:=Me.Name, Save:=acSaveNo
End Sub
Thanks George, it works.
 

Users who are viewing this thread

Top Bottom