Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank Record and Update or CancelUpdate without AddNew or Edit

Status
Not open for further replies.

weezles

Technical User
Jul 18, 2003
81
GB
Hi

I have form that opens in FormAdd mode but if the user decides not to add a record it adds a blank one.

Then if the user chooses to open this record and delete it or even just close it again, i get the error:

Update or Cancel Update withour AddNew or Edit

How can i either handle this error or prevent a blank record from being added?

Thanks

Lou
 
How are ya weezles . . . . .

[purple]Add Mode to you means New Records Only![/purple] The [blue]DataEntry Property[/blue] of the opened form is [blue]set to True.[/blue]

Don't open in [purple]Add Mode![/purple]

Calvin.gif
See Ya! . . . . . .
 
I would just open in Edit mode, and if the user wants to add a record they can hit add (*) on the nav buttons.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks guys but I really need to have the form open at a blank record.


Lou
 
As for the form adding a record "on it's own", it is often caused by some code adding a value to a bound form control. Likely place to find such code, is the on current event of the form.

The message "Update or Cancel Update withour AddNew or Edit" I only receive when trying to update a DAO recordset using recordsets and have forgotten to issue .edit or .addnew prior to altering the fields. Is this a bound form, or unbound? If bound, are you doing recordset updates at the same time there is unsaved changes to the record of the form? I don't understand how/what triggers it - have you found which line triggers the message?

I'd second the above opinions, open in edit or normal mode - but you can put in the line

[tt]docmd.gotorecord,,acnewrec[/tt]

for instance in the form load event, to open the form to a new record.

Roy-Vidar
 
Hi Roy

The form is bound and is using an autonumber for the PK. I cannot find what line triggers the message. I've tried error handling for error 3020 but cant get it to prevent it.

I think the easy option is to do as you suggested and use

docmd.gotorecord,,acnewrec

Thanks

Lou
 
weezles . . . . .

I'm afraid you may have the same problem using the [blue]DoCmd.GotoRecord Method.[/blue] There's no difference when you open a form in [blue]Add Mode.[/blue] In Add Mode you simply limited to editing/adding new records.

You say:
weezles said:
[blue]if the user decides not to add a record [purple]it adds a blank one.[/purple][/blue]
I'm not sure if your seeing this right, but if you open a form in [blue]Add Mode[/blue], it opens with a new record, ready for editing. The same as if you open the form and goto a new record using DoCmd!.

Now, the hilite here is that [blue]a record in Access has to be in [purple]Edit Mode[/purple] in order to be saved (as indicated by the pencil icon)![/blue] There are two ways to get into [purple]Edit Mode[/purple]:
[ol][li]Manual editing of a record.[/li]
[li]Writing to a record thru VBA.[/li][/ol]
So in these things I agree with [blue]RoyVidar[/blue], it appears VBA is writing to the record.

At this point I would set a BreakPoint in the OpenEvent of the form and single step till I see an assignment to one of the textboxes or possibly a DoCmd.Save or DoCmd.RunCommand acCommandSaverecord line.

Hope this helps . . . .



Calvin.gif
See Ya! . . . . . .
 
AceMan

You're right that does give the same problem.

I dont have anything like DoCmd.Save or save acCommandSaveRecord and the only assignment to any textbox is in an afterUpdate event (the only event the form has) of another field which sets its value to the same as what the user enters.

lou
 
AceMan

You're right that does give the same problem.

I dont have anything like DoCmd.Save or save acCommandSaveRecord and the only assignment to any textbox is in an afterUpdate event (the only event the form has) of another field which sets its value to the same as what the user enters.

I've tried using an OnClose event that deletes the record if all fields are empty but this doesnt work either.

lou
 
Hey there...what is the user doing to close the form when they don't want to add a record? Pushing a button? If so, what is its code?

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Or is the user perhaps 'tabbing' past the afterUpdate trigger field (& thus triggering it) that you mentioned above? Do you see the 'pencil' icon appearing or is it there OnOpen?

traingamer
 
weezles . . . . .

Out of curiosity I would love to get this solved. Did you [[blue]set a breakpoint[/blue] as I suggested and [blue]single step to the end?[/blue]

If you've never done this, try the following:
[ol][li]Open the form your opening (the called form) in design view.[/li]
[li]Double-Click the square box just to the right of the ruler. This opens the properties window for the form.[/li]
[li]Click the Events Tab.[/li]
[li]Put the cursor on the OnOpen event line and click the three elipses
Elipses.BMP
just to the right.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Sorry weezles . . . . .

I closed the internet by mistake and lost my post (quite a bit). So let me just ask!

Did you set a [blue]breakpoint[/blue] as I suggested and [blue]single step to the end?[/blue]

If you've never done this . . . let me know, I'll step ya thru it . . .


Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top