A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Check to see whether or not the record exist before close



 
 
Thread Tools Display Modes
  #1  
Old August 22nd, 2005, 04:13 AM
hngo
external usenet poster
 
Posts: n/a
Default 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  
Old August 22nd, 2005, 04:51 AM
Brian
external usenet poster
 
Posts: n/a
Default

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  
Old August 22nd, 2005, 07:38 AM
hngo
external usenet poster
 
Posts: n/a
Default

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  
Old August 22nd, 2005, 07:50 AM
Brian
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 08:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.