Results 1 to 6 of 6
  1. #1
    ExcessionOCP is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    May 2023
    Posts
    31

    Same form for creating a new item and editing an item

    Hello,



    I think I have been a bit dumb. I have a form in my application that allows users to enter a new item (my DB is an expenditure tracking system). I have been developing this as I have been learning, so when I started out I created a second version of this form that is passed the ID of the item to be edited from a listbox on a separate form and allows the user to edit a tracked item. However, if I make a change to my "create item" form, I have to replicate those changes in the "edit item" form, which have realised is a stupid thing to have to do.

    I'm thinking that I can use the "create item" form as the "edit item form", but am unsure as to the best way to do this. My "create item" form is set to be a data entry form, and the item is saved by means of a command button. I'm thinking I'd have to get the ItemID from the item selection form and pass this to the item creation form, but would this work given that that particular form is configured as a data entry form?

    Is there a better way to do this?

    Any advice would be gratefully received.

    Cheers,

    Phil

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Yes, multiple of anything is not a good idea when one will do. Whatever you use to open said form, provide a means of deciphering which mode you wish to use. This could be a combobox on your own switchboard form, which is easily modified to provide additional options. Or option buttons in a frame. Latter method would require adding controls to add options, so maybe not as slick. Pass the mode choice to the open args of the form, then depending on what that value is, code to set the form properties on the open event. You will need to learn what many of the form properties are in order to be able to use them.

    I think you will find this site to be of value going forward
    https://learn.microsoft.com/en-us/of...pi/access.form
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    take a look at the arguments in the docmd.openform method. Check out the datamode argument. acFormAdd and acFormEdit

    https://learn.microsoft.com/en-us/of...docmd.openform
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    ExcessionOCP is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    May 2023
    Posts
    31
    Brilliant! Thank you

  5. #5
    ExcessionOCP is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    May 2023
    Posts
    31
    I've got it mostly working, but I have a small issue I'm hoping you might be able to help with.

    When the form is used to enter a new item, there are some combo boxes that, when updated, pass their values to other combo box to filter the options available to the user in those other combos. This is achieved using the "AfterUpdate" trigger

    The issue is, that when I open the form using the Where condition, and set it to acFormEdit, the other combo boxes are blank. If I click into the "parent" combo boxes that have the "AfterUpdate" trigger them then the other combo boxes populate correctly, but I'd rather not make my users do that.

    So my question, is, is it possible to set a combo box to default to the record that exists in the table the form is being used to edit said record?

    Cheers,

    Phil

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I'd have to see what you got to give you a better answer but it may just be your need to call the controls AfterUpdate event

    Code:
    Private Sub Form_Load()
    
    YourComboName_AfterUpdate
    
    End sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 6
    Last Post: 05-28-2023, 08:51 PM
  2. Replies: 12
    Last Post: 06-08-2021, 09:46 AM
  3. Replies: 3
    Last Post: 05-04-2021, 07:19 AM
  4. Replies: 7
    Last Post: 11-29-2015, 07:24 AM
  5. Multi-Item Form, VBA editing on Load?
    By devander in forum Access
    Replies: 3
    Last Post: 08-03-2012, 05:36 PM

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