473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

cancelling docmd.gotorecord , , acNewRec

What's the best way to cancel the new record when doCmd.GoToRecord , ,
acNewRec is executed and before the new record is actually written to
the database.

I'm maintaining an existing Access 97 application. The main order
form's recordsource is a query. On the form is an add button that uses
doCmd.GoToRecord , , acNewRec to display an empty record and place the
user in the first field.

If the user tabs out of the first field (assuming they've typed
something in and want to continue editting the record) the record is
actually added to the database and an autoincrement field sets the
record number.

However, there's also a find button on the form and it allows the user
to search for a record even after they have clicked the add button and
before the new record has been added to the database. If they actually
search for a record, the new record is added.

What's the simplest and safest way to protect the user from this
series of events? I cannot do to much rewriting of the code or I might
cause other issues.

Thanks,
Eric
Nov 12 '05 #1
3 12508
DoCmd.RunCommand acCmdUndo

or SendKeys ({Esc},{Esc})

or teach the users to press the Esc key twice.

None of the above work if they have already done something to save the
record, e.g., (1) move off it to another record, (2) click into a subform on
the form, (3) done an explicit Save, or (4) closed the Form.

Larry Linson
Microsoft Access MVP
"Eric" <ep******@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
What's the best way to cancel the new record when doCmd.GoToRecord , ,
acNewRec is executed and before the new record is actually written to
the database.

I'm maintaining an existing Access 97 application. The main order
form's recordsource is a query. On the form is an add button that uses
doCmd.GoToRecord , , acNewRec to display an empty record and place the
user in the first field.

If the user tabs out of the first field (assuming they've typed
something in and want to continue editting the record) the record is
actually added to the database and an autoincrement field sets the
record number.

However, there's also a find button on the form and it allows the user
to search for a record even after they have clicked the add button and
before the new record has been added to the database. If they actually
search for a record, the new record is added.

What's the simplest and safest way to protect the user from this
series of events? I cannot do to much rewriting of the code or I might
cause other issues.

Thanks,
Eric

Nov 12 '05 #2
Moving into the new record should not automatically cause the entry of the
new record to begin. There must be something that is dirtying the new
record. The best solution would be to find out what it is, and avoid that.
For example, if you are programmatically setting a value, do that in the
form's BeforeInsert event instead of when you move to the new record.

If you want user confirmation before a new record is added, use the form's
BeforeUpdate event. To destroy the new entry without saving:
Me.Undo

Private Sub form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
If Msgbox("Ok to save?", vbOkCancel) <> vbOk Then
cancel = true
Me.Undo
End If
End If
End Sub

--
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.

"Eric" <ep******@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
What's the best way to cancel the new record when doCmd.GoToRecord , ,
acNewRec is executed and before the new record is actually written to
the database.

I'm maintaining an existing Access 97 application. The main order
form's recordsource is a query. On the form is an add button that uses
doCmd.GoToRecord , , acNewRec to display an empty record and place the
user in the first field.

If the user tabs out of the first field (assuming they've typed
something in and want to continue editting the record) the record is
actually added to the database and an autoincrement field sets the
record number.

However, there's also a find button on the form and it allows the user
to search for a record even after they have clicked the add button and
before the new record has been added to the database. If they actually
search for a record, the new record is added.

What's the simplest and safest way to protect the user from this
series of events? I cannot do to much rewriting of the code or I might
cause other issues.

Thanks,
Eric

Nov 12 '05 #3
Thank you for your help.

I found the problem. I had added a line of code to edit a form field
before the new record was validated.

The new record was dirty and could not be discarded by the existing
code.

I moved the code into the validation and everything works fine.

Thanks,
Eric
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: STeve Lefevre | last post by:
Hey folks -- I'm using the DoCmd.GoToRecord , , acNext to jump to the next record after the user enters a value. The problem is, it throws an error if it's already on the last record! What's the...
0
by: Timppa | last post by:
Hi, I'm converting ACCESS 2000 database to SQL Server. I have .adp project. In the .mdb I have form where I'll insert rows into two different tables using docmd.GoToRecod ,,acNewRec. In .adp...
6
by: David | last post by:
I am trying to insert an employee number into the EmpNbr field in my main table from a form where I add a new employee to my employee table. I was hoping this command would work, but it isn't. ...
5
by: Stack | last post by:
Hello, I have my data sorted on date desc in my form (multiple recs/table style). When I want to insert a new record (with my self made button and vba code(DoCmd.GoToRecord , , acNewRec)) the...
8
JAMBAI
by: JAMBAI | last post by:
Hi, Is there a way to handle single quotes when inserting the records using the below do command. Or do I need to write Insert sql. DoCmd.GoToRecord , , acNewRec Thanks Jambai
1
by: vostrixos | last post by:
Hi all,i need some help I'm working on a access project were i use a lot the docmd.gotorecord ,,next ..first ..last method and i use only once the DoCmd.GoToRecord , , acNewRec.Everything was...
3
martintallett
by: martintallett | last post by:
Help! I am trying to replace the Access Find button functionality on an old database. I can make it work when I use a basic form with bound fields and a button which shows a popup form which...
2
by: aaronyoung | last post by:
I have been using this forum to answer many questions regarding an Access database I am building (my first attempt at something like this - teaching myself as I go), and I've always been able to find...
5
by: phill86 | last post by:
Hi I have a main form that holds records for scheduled meetings, date time location etc... in that form i have a sub form that has a list of equipment resources that you can assign to the meeting in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.