Close mainform from subform

Ashleyjp1985

Registered User.
Local time
Today, 19:31
Joined
Jul 6, 2011
Messages
22
I have subform withina main form that displays records.

I have a save and close button on the subform that when cliked i want to close the mainform thereby saving the record. However i cannot get the main form to close.

this is my code, any help?

If Me.Dirty = False Then
MsgBox "No changes have been made.", vbOKOnly, "Required Data"
End If

If Me.Dirty = True Then
MsgBox "Changes have been made.Do you want to save these changes?", vbYesNo, ""
If vbYesNo = vbYes Then
DoCmd.Close acForm, "popformQcustomerbp"

Else

If vbYesNo = vbNo Then
DoCmd.RunCommand acCmdUndo
End If
End If
End If


End Sub
 
what happens when it gets to this line

If vbYesNo = vbYes Then
DoCmd.Close acForm, "popformQcustomerbp"
 
Hi,

It does nothing
 
I have restated your code in code markers, to make it easier to see.

I can now see the problem - you need to ask the question differently

either

response = msgbox("some question",vbyesno) and then test the value of response as either vbyes or vbno

or alternatively directly

if msgbox("some question",vbyesno) = vbyes then etc ...

look at the code in blue, to see.

Code:
     If Me.Dirty = False Then
          MsgBox "No changes have been made.", vbOKOnly, "Required Data"
 
     End If
 
     If Me.Dirty = True Then
[COLOR=navy]         if  (MsgBox "Changes have been made. Do you want to save these changes?", vbYesNo, "") = vbyes then[/COLOR]
[COLOR=navy]              DoCmd.Close acForm, "popformQcustomerbp"  [/COLOR]
[COLOR=navy]         Else[/COLOR]
[COLOR=navy]               DoCmd.RunCommand acCmdUndo[/COLOR]
[COLOR=navy]         End If[/COLOR]
     End If
End If
 
End Sub
 

Users who are viewing this thread

Back
Top Bottom