Form not closing properly

T

TESA0_4

Hi,
I have a Form with a Subform. If I use the cross in the top right hand
corner of the form to close it, all is well. If I use a command button with
the following code to close the form a 'white oblong' remains on the screen
in a position that matches where the subform was being displayed.
If I go back to the backup copy of the application from the start of today,
the command button works fine but not now. I cannot identify what change(s) I
have made today that has caused the command button to become partially
ineffective.
Any suggestions would be appreciated. (I'm using Access 2003 in Access2000
format).

Private Sub cmdSaveClose_Click()
On Error GoTo Err_cmdSaveClose_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close acForm, "frmHazActPlan"

Exit_cmdSaveClose_Click:
Exit Sub

Err_cmdSaveClose_Click:
MsgBox Err.Description
Resume Exit_cmdSaveClose_Click

End Sub
 
J

Jeanette Cunningham

Hi,
Make sure the close button is on the main form.
Try with the code like this

Private Sub cmdSaveClose_Click()
On Error GoTo Err_cmdSaveClose_Click

If (Me.Dirty = True) Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name

Exit_cmdSaveClose_Click:
Exit Sub

Err_cmdSaveClose_Click:
MsgBox Err.Description
Resume Exit_cmdSaveClose_Click

End Sub


Explanation:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
is very old code the wizards provide for backward compatiblilty with older
versions of access.
The most popular way to save changes is to use
If (Me.Dirty = True) Then
Me.Dirty = False
End If

To close the form that the code is running in, you don't need to hard code
the name of the form.
You can just use Me.Name
Closing the main form automatically closes the subform as well.


Jeanette Cunningham
 
T

TESA0_4

Hi Jeanette,
Thanks for your assistance.
I replaced my code with your code and the form closed but 'left behind' the
same 'white area' on the screen. If another form is opened or dragged across
the white area it refreshes to the normal gray background.
I had the command button on the footer of the main form and moved it to the
detail area of the main form but no change in the outcomes other than to get
another white area where the button was located!!
If you care to go to http://terry.timandliz.id.au/ I have posted a couple of
screenshots to illustrate what is going on.
I suppose there is a chance that I have bumped into a bug in Access.

Regards,

Terry
 
P

Paolo

Hi TESA0_4,
did you try to compact and repair the database?
If you wanna close the current form (the one who has the focus) try just with
DoCmd.Close
on your button

HTH Paolo
 
T

TESA0_4

Hi Paolo,
Have done the things you suggested. The problem does not lie in 'getting the
form to close'. The problem lies in the visual effect of having a white patch
on the screen. 'The problem' does not seem to be causing any issues for data
or the functioning of the application. If it was to remain users will ask
'why does the screen stay white?' to which I will say 'dunno' and I will tell
them to use the corner cross to close the form!!
If no smart ideas come through the forum I will rebuild the form step by
step to try and find the culprit factor.
Regards,
Terry
 
P

Paolo

Well, last suggestion
(but I dunno if it can apply 'cause you don't have any form open)

after you close the form you can try to add a me.repaint

Cheers Paolo
 
J

Jeanette Cunningham

It sounds as if something is not releasing its reference, and still trying
to stay open.
My guess is that it's something to do with the subform.
Does this happen just for this form?
Do you have any other forms open at the same time?
Make a copy of this form to test with.
See if the same thing happens with the copy.
Delete the subform from the copy and see what happens when you close the
form.


Jeanette Cunningham
 
T

TESA0_4

Hi Jeanette and Paolo,

I have worked out how to solve the problem but I cannot explain why the
problem was occurring - that goes way beyond my understanding of code and
Access.

Earlier today I installed the pop up calendar utility from
http://www.lebans.com/monthcalendar.htm that I have used very successfully in
the past. I don't really understand how it works, I just follow the recipe
and insert code where I'm told to insert code. My problematic subform had a
date field and it turns out it was the Unload code for the popup calendar
that was causing the problem. This particular piece of code is to clean-up if
a user closes the form or application with the calendar open. Testing shows
that with the calendar open the user is locked out of closing the parent form
or application so I deleted the Unload code and all is working well.

Thanks for your help and suggestions. If you're interested, the code I
deleted is as follows:

Private Sub Form_Unload(Cancel As Integer)
'This is required in case user Closes Form with the
' Calendar still open. It also handles when the
' user closes the application with the Calendar still open.
If Not mc Is Nothing Then
If mc.IsCalendar Then
Cancel = 1
Exit Sub
End If
Set mc = Nothing
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top