Results 1 to 7 of 7
  1. #1
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    Prevent new record on subform

    I have a main form with a subform control.


    when the main form is open the subform is always visible.

    It's creating a new row in my table with no data, both forms have set Properties > Other > Cycle = Current Record

    is there something I should add to the form load or on current? should I add code to delete empty records? if so, where?

    Thank you

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    How do you know it's creating a new record? It's possible that one or more fields have a default value and what you're looking at is a new record that is a potential record but has not been saved. If you don't need the defaults (it is likely 0 in a number field - see table field in design view) remove them and see if it behaves any different. If there are no values at all, something could be creating a record and saving it with nulls or empty strings but I doubt it. You can open the vb editor and put a break on the open event of the subform and step through code (if you have any) to see what might be causing a new record, assuming that is really happening.

    You could also copy, compact and zip your db and post here for analysis.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    There are default fields in the form - a date is defaulted to the current date and the request by field is auto-populated as well. so that would make sense....

    I've attached the database ... any suggestions?
    Attached Files Attached Files

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Your tables are all linked - there is no data to work with nor can the table design be checked.. You would have to delete all the linked tables in your copy and then import them (Get External Data on ribbon) and import as tables. You would not need to do this to all of them, just what's needed for your issue. Or you'd have to post a copy of the be tables. The former approach would be better for us.

    EDIT - forgot to say, be careful with linked back ends. If you copied the fe and be to another folder and deleted data from the be tables in that folder, you would not be deleting from the copy you created - you'd be deleting from the original because this fe copy is still connected to the original be. You'd be deleting production data. You must relink if you're going to play around like that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    What is the name of the main form?

    EDIT: had a chance to look at your db. I think the subform in question is frmRequests on CostEstimatingSystem main form. The subform has the DataEntry =Yes meaning it will open on a new record. Then in its Load event you start populating that new record by setting the RequestByPerson:
    Code:
     Me.RequestByPerson.Value = ResolveCurrentUserName
    Instead of populating the control like you do now try to set its default value property to the ResolveCurrentUserName custom function so you do not dirty the form.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Quote Originally Posted by Gicu View Post
    What is the name of the main form?

    EDIT: had a chance to look at your db. I think the subform in question is frmRequests on CostEstimatingSystem main form. The subform has the DataEntry =Yes meaning it will open on a new record. Then in its Load event you start populating that new record by setting the RequestByPerson:
    Code:
     Me.RequestByPerson.Value = ResolveCurrentUserName
    Instead of populating the control like you do now try to set its default value property to the ResolveCurrentUserName custom function so you do not dirty the form.

    Cheers,

    I had those fields already with the default values so I removed from the FormLoad but it still created a new record.

  7. #7
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    As micron said it is hard to debug a linked app, try to import the tables needed for those forms (main\sub) to open properly, compact it, zip it and uploaded here.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-15-2018, 09:11 AM
  2. Replies: 1
    Last Post: 08-08-2017, 03:14 PM
  3. Prevent subform being set focus
    By paramesium in forum Forms
    Replies: 9
    Last Post: 12-05-2013, 11:55 AM
  4. Replies: 3
    Last Post: 09-19-2012, 07:34 AM
  5. Replies: 2
    Last Post: 12-07-2011, 02:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums