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 |
#1
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
I set up the following code listed below. The form is set up as a
multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#2
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.HRnum) Then MsgBox "You must enter an HR number.", vbCritical, "Data Validation Failure" Cancel = True End Sub The value of vbCancel is 2 The value of True is -1 "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#3
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
i tested your code on a Continuous form, and it ran consistently no matter
what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#4
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
When I re-tested, it seemed to work; I guess I had been working too long.
Thank you. "tina" wrote: i tested your code on a Continuous form, and it ran consistently no matter what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#5
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
no problem
"rmcompute" wrote in message ... When I re-tested, it seemed to work; I guess I had been working too long. Thank you. "tina" wrote: i tested your code on a Continuous form, and it ran consistently no matter what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#6
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
Your code DOES NOT work!!!!
"rmcompute" wrote in message ... When I re-tested, it seemed to work; I guess I had been working too long. Thank you. "tina" wrote: i tested your code on a Continuous form, and it ran consistently no matter what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#7
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
Pat, i tested rmcompute's code in an A2K db running in A2003 on OS Win2KPro.
i pasted it "as is" from his post, changing only the control name HRnum to the name of a control on my form. the code runs fine on my setup. did you have a different result? perhaps in another version of Access or Windows? hth "Pat Hartman(MVP)" wrote in message ... Your code DOES NOT work!!!! "rmcompute" wrote in message ... When I re-tested, it seemed to work; I guess I had been working too long. Thank you. "tina" wrote: i tested your code on a Continuous form, and it ran consistently no matter what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#8
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
Pat, i tested rmcompute's code in an A2K db running in A2003 on OS Win2KPro.
i pasted it "as is" from his post, changing only the control name HRnum to the name of a control on my form. the code runs fine on my setup. did you have a different result? perhaps in another version of Access or Windows? hth "Pat Hartman(MVP)" wrote in message ... Your code DOES NOT work!!!! "rmcompute" wrote in message ... When I re-tested, it seemed to work; I guess I had been working too long. Thank you. "tina" wrote: i tested your code on a Continuous form, and it ran consistently no matter what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#9
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
As I already said -
The value of vbCancel is 2 The value of True is -1 That means that if the user chooses the cancel button, the message box will return a 2 and place that value in the Cancel argument. Access is expecting 0 or -1 as a value for the Cancel argument. If Cancel = -1, Access will cancel the update. If Cancel is anything else (I'm assuming that that is the way the test is coded), the record is saved. Therefore, if the record is saved even when vbCancel is chosen, the code does not work! Just because a piece of code compiles or doesn't raise an error, doesn't mean that it is correct. Check the table and you will see the invalid records there. "tina" wrote in message ... Pat, i tested rmcompute's code in an A2K db running in A2003 on OS Win2KPro. i pasted it "as is" from his post, changing only the control name HRnum to the name of a control on my form. the code runs fine on my setup. did you have a different result? perhaps in another version of Access or Windows? hth "Pat Hartman(MVP)" wrote in message ... Your code DOES NOT work!!!! "rmcompute" wrote in message ... When I re-tested, it seemed to work; I guess I had been working too long. Thank you. "tina" wrote: i tested your code on a Continuous form, and it ran consistently no matter what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
#10
|
|||
|
|||
Data Testing To Prevent Saving Bad Data
Pat, Tina,
I re-tested the code. As mentioned before it is placed in Sub Form_BeforeUpdate. When I set the Cancel variable to anything except False, I could not save the record. It keeps looping through the Before Update Procedure. RMConfused. "Pat Hartman(MVP)" wrote: As I already said - The value of vbCancel is 2 The value of True is -1 That means that if the user chooses the cancel button, the message box will return a 2 and place that value in the Cancel argument. Access is expecting 0 or -1 as a value for the Cancel argument. If Cancel = -1, Access will cancel the update. If Cancel is anything else (I'm assuming that that is the way the test is coded), the record is saved. Therefore, if the record is saved even when vbCancel is chosen, the code does not work! Just because a piece of code compiles or doesn't raise an error, doesn't mean that it is correct. Check the table and you will see the invalid records there. "tina" wrote in message ... Pat, i tested rmcompute's code in an A2K db running in A2003 on OS Win2KPro. i pasted it "as is" from his post, changing only the control name HRnum to the name of a control on my form. the code runs fine on my setup. did you have a different result? perhaps in another version of Access or Windows? hth "Pat Hartman(MVP)" wrote in message ... Your code DOES NOT work!!!! "rmcompute" wrote in message ... When I re-tested, it seemed to work; I guess I had been working too long. Thank you. "tina" wrote: i tested your code on a Continuous form, and it ran consistently no matter what i did to "save" either a new record or an edit to an existing record - pressing Shift+Enter, or clicking the toolbar icon, or choosing menu Records | Save record, or moving to another record - either next or previous, or closing the form. this is the expected result. are you sure that the new record is actually being saved when you "move to another record and click the Save icon"? what version of Access are you using? and is any other code running on the form's BeforeUpdate event? hth "rmcompute" wrote in message ... I set up the following code listed below. The form is set up as a multi-record form (Default View = Continuous Forms). The test is successful on existing records preventing the user from going forward. When a new record is added, the user can beat the system by clicking on the next line and then clicking the save icon on the tool bar. Can the system be set up in such a way that if the user adds a new record and the test fails, that he is prevented from saving the record or even going to the next line by clicking the mouse. Could the toolbar be disabled, preventing the user from being able to save when the test fails ? Is any other code required in the BeforeUpdate procedure to prevent the user from going forward until the error is addressed ? Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.HRnum) Then Cancel = MsgBox("You must enter an HR number.", vbCritical, "Data Validation Failure") End End Sub |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cross program data sharing | m_jurrens | Powerpoint | 1 | December 16th, 2005 04:36 PM |
cross office program data sharing | m_jurrens | General Discussion | 0 | December 16th, 2005 03:36 PM |
Query does not order the same data in the same way | Milković Aleksandar | Running & Setting Up Queries | 10 | December 15th, 2005 12:01 PM |
How do I get 3 series in sync with the x-axis? | zizbird | Charts and Charting | 10 | October 25th, 2004 01:23 PM |
How to create graphs in a monthly report where the base data can change | John Clarke | Charts and Charting | 3 | June 25th, 2004 02:22 AM |