If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#21
|
|||
|
|||
Using a Form to open 2nd form
Do you have a button that closes the form?
If so, it goes in the button's Click event, before the close. If not, this issue does not apply. Access will give you the message when you close the bound form. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Robin" wrote in message news Where do I put the following code to make this work? If Me.Dirty Then Me.Dirty = False End If thnaks, Robin "Allen Browne" wrote: If you add the code to force the save, the save will fail. It will generate a trappable error. As a result the close will not occur. I think that's exactly what you want? "Robin" wrote in message ... Is there a way NOT to close the form when a required field is left blank. I want to force the user to put something in this field if left blank. The Data that they need to put in will be Yes or No. Thanks, Robin "Allen Browne" wrote: This is a bug in Access. If the record cannot be saved with you use the Close action (macro) or method (VBA code), it silently discards the entry! If fails to give you the error message you expect More info: http://allenbrowne.com/bug-01.html As the article explains, you can avert the problem by explicitly saving the record before you use Close, e.g.: If Me.Dirty Then Me.Dirty = False End If DoCmd.Close acForm, Me.name |
#22
|
|||
|
|||
Using a Form to open 2nd form
I have a close command button at the bottom of the form. I add the code that
you suggested that I use but It still will not work. When I click on the button it goes to the first form. It needs to give me an error msg. so that the user can make the corrections. Here is the code that is in the click event section: Private Sub Close_Form_Click() On Error GoTo Err_Close_Form_Click If Me.Dirty Then Me.Dirty = False End If DoCmd.Close acForm, Me.Name Exit_Close_Form_Click: Exit Sub Err_Close_Form_Click: MsgBox Err.Description Resume Exit_Close_Form_Click End Sub Please tell me what I am doing wrong. Thanks you again for all your help. Robin "Allen Browne" wrote: Do you have a button that closes the form? If so, it goes in the button's Click event, before the close. If not, this issue does not apply. Access will give you the message when you close the bound form. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Robin" wrote in message news Where do I put the following code to make this work? If Me.Dirty Then Me.Dirty = False End If thnaks, Robin "Allen Browne" wrote: If you add the code to force the save, the save will fail. It will generate a trappable error. As a result the close will not occur. I think that's exactly what you want? "Robin" wrote in message ... Is there a way NOT to close the form when a required field is left blank. I want to force the user to put something in this field if left blank. The Data that they need to put in will be Yes or No. Thanks, Robin "Allen Browne" wrote: This is a bug in Access. If the record cannot be saved with you use the Close action (macro) or method (VBA code), it silently discards the entry! If fails to give you the error message you expect More info: http://allenbrowne.com/bug-01.html As the article explains, you can avert the problem by explicitly saving the record before you use Close, e.g.: If Me.Dirty Then Me.Dirty = False End If DoCmd.Close acForm, Me.name |
#23
|
|||
|
|||
Using a Form to open 2nd form
You have already set up the Form_BeforeUpdate event so that it complains if
a required field is left blank. That means it is impossible to save the form once an entry has been started unless the required field is filled in. Setting Dirty to False fires Form_BeforeUpdate if there is any entry in progress. That takes care of the required field. The only other scenario is where the user has *not* even started any entry. This usually means they changed their mind and decided no to make an entry. The normal process would be to accept that there is no entry at all and allow them to close the form. If you want to insist that they MUST enter a record, and they cannot close the form until they do so, you could add a condition that tests to see if they are still at the new record, and don't allow the close for that case. It does not seem like a good idea to me, but the code would look like this: Private Sub Close_Form_Click() On Error GoTo Err_Close_Form_Click If Me.Dirty Then Me.Dirty = False End If If Me.NewRecord Then MsgBox "You cannot get outa here until you enter something!" Else DoCmd.Close acForm, Me.Name End If Exit_Close_Form_Click: Exit Sub Err_Close_Form_Click: MsgBox Err.Description Resume Exit_Close_Form_Click End Sub You would need to make the form modal, and turn off its Close button and Control Box to make this reliable. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Robin" wrote in message ... I have a close command button at the bottom of the form. I add the code that you suggested that I use but It still will not work. When I click on the button it goes to the first form. It needs to give me an error msg. so that the user can make the corrections. Here is the code that is in the click event section: Private Sub Close_Form_Click() On Error GoTo Err_Close_Form_Click If Me.Dirty Then Me.Dirty = False End If DoCmd.Close acForm, Me.Name Exit_Close_Form_Click: Exit Sub Err_Close_Form_Click: MsgBox Err.Description Resume Exit_Close_Form_Click End Sub Please tell me what I am doing wrong. Thanks you again for all your help. Robin "Allen Browne" wrote: Do you have a button that closes the form? If so, it goes in the button's Click event, before the close. If not, this issue does not apply. Access will give you the message when you close the bound form. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Robin" wrote in message news Where do I put the following code to make this work? If Me.Dirty Then Me.Dirty = False End If thnaks, Robin "Allen Browne" wrote: If you add the code to force the save, the save will fail. It will generate a trappable error. As a result the close will not occur. I think that's exactly what you want? "Robin" wrote in message ... Is there a way NOT to close the form when a required field is left blank. I want to force the user to put something in this field if left blank. The Data that they need to put in will be Yes or No. Thanks, Robin "Allen Browne" wrote: This is a bug in Access. If the record cannot be saved with you use the Close action (macro) or method (VBA code), it silently discards the entry! If fails to give you the error message you expect More info: http://allenbrowne.com/bug-01.html As the article explains, you can avert the problem by explicitly saving the record before you use Close, e.g.: If Me.Dirty Then Me.Dirty = False End If DoCmd.Close acForm, Me.name |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Visio Shortcuts | [email protected] | Visio | 1 | December 28th, 2006 11:28 PM |
Parameter thru Form Dialog Box for REPORT | Sandy | Setting Up & Running Reports | 16 | January 10th, 2006 10:06 AM |
Form does not open - Access says it is open | DMUM | Using Forms | 5 | December 14th, 2005 09:32 PM |
Form won't open report from preview button | jwr | Using Forms | 5 | October 29th, 2005 04:53 PM |
auto entry into second table after update | Tony | New Users | 13 | July 9th, 2004 10:42 PM |