UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Two New Records Added, Access 2016    
 
   
tobyhanna
post May 21 2019, 03:03 PM
Post#1



Posts: 144
Joined: 7-February 06



Hello,

I have one form with a subform listing data in datasheet format. When the user clicks an "Add New" or "Edit" command button on this first form, a detail form opens to display the all fields to add or for the selected record. I open this detail form in either add mode to a new record or in edit mode to the selected record.

Edit works fine. Add works kind of. I've removed the "DoCmd.GoToRecord , , acNewRec" and still it adds two records. In Add mode, when the detail form opens, a "new" record appears in the table with a new autoID. However, the field associated with this autoID states a value of NULL. When I set a field value, a "second" new record appears with a new autoID. How can I avoid this?

I've trapped and traced, when the detail form opens, the right number of records exists in the table. After the Form_Open runs, the right number of records exists. As soon as the Form_Open steps to the Form_Load, the "second" record appears, before any code (except error trapping).

Thanks for any help,
Liesl
Go to the top of the page
 
theDBguy
post May 21 2019, 03:12 PM
Post#2


Access Wiki and Forums Moderator
Posts: 76,084
Joined: 19-June 07
From: SunnySandyEggo


Hi Liesl. Sounds like some code may be adding a new record to the table as soon as it opens or when it closes. Try disabling any code first to test it out and slowly turn them on one by one to find out which one is doing it.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
tobyhanna
post May 21 2019, 03:53 PM
Post#3



Posts: 144
Joined: 7-February 06



Thanks DBGuy,

It's a bit more complicated than what I initially wrote. My detail form has a subform and sets a SourceForm for this subform depending upon a previously selected value. The first new record is added when the detail form sets it's SourceForm. I took your suggestion and while I left in debug.print for testing I added exit sub just after for this SourceForm FormOpen, FormLoad (no code in FormCurrent). Everything loads but of course my drop-downs and listboxes. But the same two records are added. I just can't seem to grab the first one as the autoID is NULL. So strange.

In my detail form, the offending line of code is below, where sformName is a dLookup
CODE
Me.frmMethodNotesEditSubform.SourceObject = sFormName


It's as if the first new record is added with two pieces of information but when the detail subform opens the info is blank and it's on to the next new record.

I just discovered the subforms have Filters set that I can't delete. Meaning I delete the filter in the property list and close the form but they return when I reopen to view the properties. Perhaps there is something wrong with my forms or the Filter setting is messing with me.

Thanks for changing the direction of my endless circle.

Liesl
Go to the top of the page
 
theDBguy
post May 21 2019, 04:16 PM
Post#4


Access Wiki and Forums Moderator
Posts: 76,084
Joined: 19-June 07
From: SunnySandyEggo


It would be nice if we could examine the forms too. Maybe we'll see something you could be missing because you've been looking at it too long.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
tobyhanna
post May 21 2019, 04:17 PM
Post#5



Posts: 144
Joined: 7-February 06



I agree. It will take me some time to make a smaller, appropriate version...

Thanks,
Liesl
Go to the top of the page
 
theDBguy
post May 21 2019, 04:27 PM
Post#6


Access Wiki and Forums Moderator
Posts: 76,084
Joined: 19-June 07
From: SunnySandyEggo


Hi. If you want to take a shortcut, you can email me the whole thing, and I'll take a look.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
tobyhanna
post May 21 2019, 06:50 PM
Post#7



Posts: 144
Joined: 7-February 06



Thank you for the offer. I found a setting that needed to be cleared, the SourceObject of the detail form "defaulted" to one of the subforms so it closed and opened two different subforms and caused all kinds havoc. And turning FilterOnLoad to No and deleting the "default" filter helped too. Thank you again, your initial response helped me more than you know.

Liesl
Go to the top of the page
 
theDBguy
post May 21 2019, 08:13 PM
Post#8


Access Wiki and Forums Moderator
Posts: 76,084
Joined: 19-June 07
From: SunnySandyEggo


Hi Liesl. Congratulations! Glad to hear you got it sorted out. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    25th August 2019 - 10:32 AM