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
|
|||
|
|||
Check to see whether or not the record exist before close
Hi,
Is there away that we can check to see whether or not the record is exist in a database (the PK is MyID). IF the record exist ask before save. If new record save the record. Please help, many thanks in advance |
#2
|
|||
|
|||
If Form.NewRecord Then...Else...End If
However, if you are using bound controls, Access automatically saves the record (whether new or changed) upon closing the form or navigating to a new record, so you may want to set this up to give the user an option to cancel. If Not Form.NewRecord and Me.Dirty Then If Not MsgBox("Do you wish to save your changes?", vbExclamation + vbYesNo, "Update?") = vbYes Then Me.Undo End If "hngo" wrote: Hi, Is there away that we can check to see whether or not the record is exist in a database (the PK is MyID). IF the record exist ask before save. If new record save the record. Please help, many thanks in advance |
#3
|
|||
|
|||
Hi Brian,
new record is save over the existing data. New record has not been add to the table. What have I done wrong? (the code has been enter in the after update event) "Brian" wrote: If Form.NewRecord Then...Else...End If However, if you are using bound controls, Access automatically saves the record (whether new or changed) upon closing the form or navigating to a new record, so you may want to set this up to give the user an option to cancel. If Not Form.NewRecord and Me.Dirty Then If Not MsgBox("Do you wish to save your changes?", vbExclamation + vbYesNo, "Update?") = vbYes Then Me.Undo End If "hngo" wrote: Hi, Is there away that we can check to see whether or not the record is exist in a database (the PK is MyID). IF the record exist ask before save. If new record save the record. Please help, many thanks in advance |
#4
|
|||
|
|||
AfterUpdate doesn't happen until after the record is saved. Move it to
Form_BeforeUpdate & Cancel/Undo if the user answers No: Private Sub Form_BeforeUpdate(Cancel As Integer) If Not Form.NewRecord and Me.Dirty Then If MsgBox("Do you wish to save your changes?", vbExclamation + vbYesNo, "Save changes?") = vbNo Then Cancel = True Me.Undo End If End If End Sub "hngo" wrote: Hi Brian, new record is save over the existing data. New record has not been add to the table. What have I done wrong? (the code has been enter in the after update event) "Brian" wrote: If Form.NewRecord Then...Else...End If However, if you are using bound controls, Access automatically saves the record (whether new or changed) upon closing the form or navigating to a new record, so you may want to set this up to give the user an option to cancel. If Not Form.NewRecord and Me.Dirty Then If Not MsgBox("Do you wish to save your changes?", vbExclamation + vbYesNo, "Update?") = vbYes Then Me.Undo End If "hngo" wrote: Hi, Is there away that we can check to see whether or not the record is exist in a database (the PK is MyID). IF the record exist ask before save. If new record save the record. Please help, many thanks in advance |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Spell Check one record | Neal | Using Forms | 0 | June 28th, 2005 05:54 PM |
check to see if a record already exists | Dan | General Discussion | 2 | May 4th, 2005 04:27 AM |
A code that will tell me if a record alreadya exist or not. | kenjikimura23 | Using Forms | 1 | March 24th, 2005 02:21 PM |
Gaps in Form "Record Number Boxes" | EricRod | New Users | 5 | March 5th, 2005 02:01 AM |
Prevent Blank Records being written. Need Help. | Robert Nusz @ DPS | Using Forms | 4 | December 29th, 2004 05:15 PM |