recordset saving - Now stuck with Access

S

Stuck with Excel

I have a database which has mutliple forms.
The main form (search parameters) creates a recordset using SQL to return
the results in a ListBox. When I click on a desired record on the results it
opens another form.

The problem I have is that I am using the dirty property to search for
changes on the form and if there are changes to save and close the form.

Code as follows:
Private Sub cmbclose_Click()
On Error GoTo Err_cmbClose_Click

If Form_frmMaintainProject.Dirty = True Then
If MsgBox("This record has been changed, do you want to save changes
and close?", vbYesNo) = vbYes Then
Call txtNowStamp_Change
Call TxtNameStamp_Change
ElseIf vbNo Then
Exit Sub
End If
DoCmd.Close
ElseIf Form_frmMaintainProject.Dirty = False Then
DoCmd.Close
End If

Exit_cmbClose_Click:
Exit Sub

Err_cmbClose_Click:
MsgBox Err.Description
Resume Exit_cmbClose_Click

End Sub

The problem I have is that when I run the above the form switches focus to
the search form and I have to click the close button to save the record and
close the form. This only happens when the Dirty = True. When Dirty = False
i.e. no changes the form closes fine as it just works of a docmd.close. I
think that the fact that the recordset is bound to the search form and not
the details form is where my problem lies. Is there a way I can get this to
run without switching the form focus back to the search parm form?

This is on Access 97 (back in the stone age which is not helping)
 
E

Essexbug

Not to worry. I solved the problem

It turned out that the problem was not with the code at all!

An autoexec macro had become embedded in a majority of controls on the form
I was coding to. This macro was causing the search parm form to be brought
to the front before the code to close the form was run. The code itself was
fine.

Me.Dirty works well for the check for changes on a record.
 

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