Prev: Change color on date field in form for re-certification
Next: Building a "save form and open next form" button macro
From: Dennis on 14 Apr 2010 13:03 Hi, I'm running Access via Office XP Pro on Windows 7. I've already read the other forum discussion on this subject & I'm still having a problem. I have a form called frmWarranty_Search. It can be run from either a main menu program (in which case the OpenArgs is set to ""). Or it can be run from other programs (in which case the calling program's name is set in OpenArgs). In the form, I have a close button. Here is the code: -------- S t a r t C o d e ------------ Private Sub cbClose_Click() If pstrCalledBy = "" Then DoCmd.Close acForm, Me.Name ' Close the form Else Me.Visible = False ' Hide the form & let calling form close End If End Sub ----------- E n d C o d e ------------------- pstrCalledBy is set by the OnLoad event. If OpenArgs = "", then this variable is set to "" otherwise it has the name of the calling program. When I run the form directly the the Access forms menu or calling it from one of the programs, I receive the following error when I hit the close button: Microsoft Visual Basic Run-time error '2501' The Close action was canceled. I the have a End, Debug, or Help button. I hit the debug button and it takes me to the line: DoCmd.Close acForm, Me.Name ' Close the form I lookup up the value of me.name and it is the form name. I also changed Me.Name to cpstrFormName, which is a constant with the form'a name. I still received the same error. How do I fix this? Thanks, Dennis
From: Marshall Barton on 14 Apr 2010 14:21 Dennis wrote: >I'm running Access via Office XP Pro on Windows 7. > >I've already read the other forum discussion on this subject & I'm still >having a problem. > >I have a form called frmWarranty_Search. It can be run from either a main >menu program (in which case the OpenArgs is set to ""). Or it can be run >from other programs (in which case the calling program's name is set in >OpenArgs). > >In the form, I have a close button. Here is the code: >-------- S t a r t C o d e ------------ >Private Sub cbClose_Click() > > If pstrCalledBy = "" Then > DoCmd.Close acForm, Me.Name ' Close >the form > Else > Me.Visible = False ' Hide >the form & let calling form close > End If > >End Sub > ----------- E n d C o d e ------------------- > >pstrCalledBy is set by the OnLoad event. If OpenArgs = "", then this >variable is set to "" otherwise it has the name of the calling program. > >When I run the form directly the the Access forms menu or calling it from >one of the programs, I receive the following error when I hit the close >button: > >Microsoft Visual Basic >Run-time error '2501' > >The Close action was canceled. > >I the have a End, Debug, or Help button. > >I hit the debug button and it takes me to the line: > > DoCmd.Close acForm, Me.Name ' Close >the form > That error indicates that the form can not be closed at that point. Common causes are code in the form's Close or Unload events that specifically cancels the event or, if the form is bound, the current record can not be saved because it fails a validation check. -- Marsh MVP [MS Access]
From: Dennis on 14 Apr 2010 17:43 Marshall, Your comment: That error indicates that the form can not be closed at that point. Common causes are: 1. code in the form's Close or Unload I have no code in the Unload event. Here is the code in the cbClose and On Close Event: Private Sub cbClose_Click() Call Form_Close End Sub Here is code in On Close event: Private Sub Form_Close() If pstrCalledBy = "" Then DoCmd.Close acForm, Me.Name ' Close the form Else Me.Visible = False ' Hide the form & let calling form close End If End Sub 2. if the form is bound, the current record can not be saved because it fails a validation check. This is supposed to be a display only screen. There is no way to alter the data when it is displayed. Currently, this is a continuous form. There is an invisible button that is layed over the data control fields so there is no way to alter the data fields. How do I make sure it is a display only form (other than the unbound fields at the top which I used for selecting the customer and invoice).? Any way to determine what is cancelling the update? Dennis
From: Bob Quintal on 14 Apr 2010 18:33 =?Utf-8?B?RGVubmlz?= <Dennis(a)discussions.microsoft.com> wrote in news:38859089-5D5D-478F-9973-679255ED4723(a)microsoft.com: > Marshall, > > Your comment: That error indicates that the form can not be > closed at that point. Common causes are: > > 1. code in the form's Close or Unload > I have no code in the Unload event. > > Here is the code in the cbClose and On Close Event: > > Private Sub cbClose_Click() > Call Form_Close > End Sub > > > Here is code in On Close event: > > Private Sub Form_Close() > If pstrCalledBy = "" Then > DoCmd.Close acForm, Me.Name > ' Close > the form > Else > Me.Visible = False > ' Hide > the form & let calling form close > End If > End Sub > > > 2. if the form is bound, the current record can not be saved > because it fails a validation check. > > This is supposed to be a display only screen. There is no way to > alter the data when it is displayed. Currently, this is a > continuous form. There is an invisible button that is layed over > the data control fields so there is no way to alter the data > fields. > > How do I make sure it is a display only form (other than the > unbound fields at the top which I used for selecting the customer > and invoice).? > > > Any way to determine what is cancelling the update? > > Dennis > You are calling the form_close event when calling the form_close event when calling the form_close event when calling the form_close event when calling the form_close event .....ad infinitum Move the code to the cbClose_Click event -- Bob Quintal PA is y I've altered my email address.
From: Dennis on 14 Apr 2010 20:38 Bob, I originally had the code in the cbClose_Click event and it caused the same issue. However, maybe I know why. Originally, I had the following code in the On Close Event: Call cbClose_Click Which would result in the same thing. Ok, now that we know what is happening, here is the next question. My objective is: If the form is called by an external form, then the form should be make invisible by Me.Visible = False. If the form was NOT called by external form, then it should close. This worked fine with the Close button, but did not work with the Close X button. Therefore, I modified the On Close event. Obviously, this did not work. So how do I do the above? Dennis
|
Next
|
Last
Pages: 1 2 3 4 Prev: Change color on date field in form for re-certification Next: Building a "save form and open next form" button macro |