Close Form Button will not work?

tafnuef1

Registered User.
Local time
Yesterday, 20:11
Joined
Apr 22, 2010
Messages
43
I placed a control buttont o close my form and It continues to enable a few of my fields before it will actually close. You have to click it several times before it will close correctly. I first had it in my mainform and it was behaving that way and thought perhaps I needed it in my subform instead but still it is giving me same behavior. It will tab to 2-4 of my fields before it will close? Anyone experiencing this? and what is the work around it?:confused:
 
Do you have any code in the Unload or Close event of your form?
 
Also, what code are you using for closing the form - exactly?
 
Actually it works if you don't click the "Clear All" button. But once I click save then close form it then pops into a field and you have to hit close form 2 or 3 or more times before it actually closes. Below is my "Save" Code and my "Close Form" code.

Clear All: (Which is actually a Undo All command it doesn't save the record)
Private Sub Undo_All_Click()
On Error GoTo Err_Undo_All_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70


Me.Batch_Number_ID.SetFocus
Me.Batch_Number_ID.Enabled = True
Me.Document_Count.Enabled = False
Me.Date_of_Audit.Enabled = False
Me.Document_Type.Enabled = False
Me.Prepper_Name.Enabled = False
Me.Indexer_Name.Enabled = False
Me.Audit_Errors_Subform.Form.Prepper_Error.Enabled = False
Me.Audit_Errors_Subform.Form.Indexer_Error.Enabled = False



Exit_Undo_All_Click:
Exit Sub
Err_Undo_All_Click:
MsgBox Err.Description
Resume Exit_Undo_All_Click

End Sub



CLOSE:

Private Sub Close_All_Click()
On Error GoTo Err_Close_All_Click

DoCmd.Close
Exit_Close_All_Click:
Exit Sub
Err_Close_All_Click:
MsgBox Err.Description
Resume Exit_Close_All_Click

End Sub
 
I can't remember what those menu items represent but I think you might be Selecting and Deleting?

What version of Access are you using? You should avoid using those commands. Simply Delete the current record using the SQL DELETE action. Example:

Dim db as DAO.Database
Set db = Currentdb
db.execute "DELETE FROM MyTable WHERE ID = 1"

Here's a link on the DELETE statement:
http://www.techonthenet.com/sql/delete.php

You would however need to be careful with this, so my advice would be to ensure that you disable the button when a "Clear All" shouldn't be performed.

Once you perform a DELETE you should call Me.Requery as well.

Another thing I noted was, Enable your control before setting focus to it so just swap it like this:

Me.Batch_Number_ID.Enabled = True
Me.Batch_Number_ID.SetFocus
...

Finally, ensure that the close button is actually located on your MAIN FORM not on any of the subforms.
 
Also, just a bit about the close code.

You should use:

DoCmd.Close acForm, Me.Name, acSaveNo

and not just

DoCmd.Close

this way it explicitly knows that you want to close a form, the form name (leave Me.Name if the code is on the form in question as that will provide the name without you having to modify any code) and then the acSaveNo just makes it so it won't save any DESIGN CHANGES to the form (it has nothing to do with saving or not saving records).
 
Made a few changes to my form.. now I am back to this.. What is wrong with my close form button?

Private Sub Close_Click()
On Error GoTo Err_Close_Click

If Me.Dirty Then Me.Dirty = False
DoCmd.Close
Exit_Close_Click:
Exit Sub
Err_Close_Click:
MsgBox Err.Description
Resume Exit_Close_Click

End Sub
 
What is wrong with it in what respect?

By the way, you should avoid one-line IF statements. Close it properly:
Code:
If Me.Dirty Then 
    Me.Dirty = False
End If
Docmd.close me.name, acSaveNo
 
What is wrong with it in what respect?

By the way, you should avoid one-line IF statements.
I would agree for 90% of the time but there are situations it really makes no sense to do and this is one of them.

I always use

If Me.Dirty Then Me.Dirty = False

as a one liner. Putting it into 3 lines seems obsessive/compulsive.
 
I would agree for 90% of the time but there are situations it really makes no sense to do and this is one of them.

I always use

If Me.Dirty Then Me.Dirty = False

as a one liner. Putting it into 3 lines seems obsessive/compulsive.
True. I use them (sparingly) but for legibility I wrote it so that the OP can see whether he/she wants to do something inside the block or not. Also, depends on writing style too though.
 
Once I click the close form button goes and sets focus on the first control on my form. I click again, it goes to the second control. it takes about 3-4 clicks before it closes???
 
Post a stripped-down version of your database and we would have a look.
 
Are you using the Database on two different versions of Access? i.e. Access 2003 and Access 2007

The reason I ask is because I had the same problem, the easiest fix was to determine the system you are going to use and recreate the close buttons using that version.
 

Users who are viewing this thread

Back
Top Bottom