Results 1 to 11 of 11
  1. #1
    kiri19 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Ottawa, Canada
    Posts
    18

    Issues with buttons, save, update and delete buttons

    Hi i am having issues first of all with a combo box that autopopulates a form, everytime i select an entry from the combo box it creates a new entry in the table when i close the form.


    Also i need help creating add, delete and update buttons on the form so that the users enters or modifies info in the fields and then it saves the record or updates it.

    Same for update button, updates the records populated by the combobox and only saves when the button is clicked on .
    Also a delete button with the same idea.

    for the onclick even for the add button i have: DoCmd.RunCommand acCmdSaveRecord, this seems to be working fine, when the combobox autopopulates it also add a new record of the same info.


    for the delete button i have: DoCmd.RunCommand acCmdDeleteRecord but it does not seem to be deleting.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Form is bound to table/query? Record entry/edit committed to table when form closes, move to new record, or run code.

    Really don't have enough info to analyze issue. Post complete procedure or provide database. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    kiri19 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Ottawa, Canada
    Posts
    18
    I apologize i was in a rush and could not explain properly.
    I have a combobox that autopopulates fields. Also i have buttons as users are looking for a friendly interface. I have 3 buttons: ADD NEW CLIENT, DELETE AND UPDATE.
    When the form is first open it is blank so the user can enter a new record, so far i have set the ADD NEW CLIENT button to redirect to reload the form as access save the entry automatically once the form is closed , this is working fine so far.

    So now what i am looking for is to use the combobox to autopopulate the form, once autopopulated the user can edit the record and then click on the UPDATE button and it saves the changes not create a new entry because it creates duplicates. Same thing for the delete button user selects an entry in the combobox and clicks the DELETE button and it deletes the entry currently populated.

  4. #4
    kiri19 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Ottawa, Canada
    Posts
    18
    This is a bound form by the way

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    The combobox is bound to field? If you open the form to an existing record then selecting item in combobox is changing value in record. If you open form to new record, then selecting item in combobox initiates a record in table.

    Can't use this bound combobox to 'autopopulate' the form. If you want to use combobox to enter criteria to find existing record, then it must be an unbound control, otherwise you are changing value or starting new record. Review this tutorial for one method of finding record.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    kiri19 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Ottawa, Canada
    Posts
    18
    The combobox is unbound.
    I have created 2 comboboxes to test, for one i used " I want the combo box to get the values from another table or query" for the other one i used " Find a record on my form based on the value I selected in my combo box", for both the values show up. Now to populate the textfields in my form i used a code like this
    Me.lastname.Value = searchcombo.Column(1)
    Me.firstname.Value = searchcombo.Column(2) and so on for each field, not sure if this is the best way to do it. So everytime a value is selected in the combobox it creates a new entry in the table...i think this is where the problem resides.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Sorry, forgot to post the tutorial link http://datapigtechnologies.com/flash...tomfilter.html

    Don't refer to the searchcombo in the textbox expressions.

    If the searchcombo is unbound (no ControlSource) then a new record should not initiate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by kiri19 View Post

    ...for the delete button i have: DoCmd.RunCommand acCmdDeleteRecord but it does not seem to be deleting.
    If you try to Delete a Record that is New, i.e. it has not been Saved, you can't...there is no Record to Delete! In this circumstance you'd need to Undo the data, simply using Me.Undo.

    If this is a Record that has been Saved, I believe you need to 'Select' the Record before Deleting it:

    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord


    As you've found out, trying to use Access in a manner that goes against the native way it is intended to be used, and against the way that experienced Access users are accustomed to it working, i.e. only Saving a Record if a Save button is clicked, is
    usually problematic. Also, if your button is actually called/labeled 'ADD NEW CLIENT,' most users, certainly all experienced Access users, are going to assume that they need to click the button in order to start a New Record, not to Save the one they just filled in.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    kiri19 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Ottawa, Canada
    Posts
    18
    The tutorial you sent me is exactly what i was looking for , now one question it seems to not work when Data entry for the form is set to Yes. Now the problem is that my users want to get an empty form when they open the form so that they start enter typing in the field

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by kiri19 View Post

    ...it seems to not work when Data entry for the form is set to Yes...
    Set the Data Entry Property to No and use this code:

    Code:
    Private Sub Form_Load()
      DoCmd.GoToRecord , , acNewRec
    End Sub


    When the Form opens, all existing Records will be in it, but it will open on a new, blank Record.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    kiri19 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Location
    Ottawa, Canada
    Posts
    18
    Thanks a lot, i think i am ready to publish my first app. excited!!!

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

Similar Threads

  1. Replies: 4
    Last Post: 05-08-2012, 08:07 AM
  2. Option Buttons & After Update code - Linked
    By Norbayah in forum Forms
    Replies: 2
    Last Post: 02-28-2012, 09:52 PM
  3. Buttons!
    By kp123 in forum Access
    Replies: 5
    Last Post: 12-08-2011, 04:22 AM
  4. command buttons
    By hijack61 in forum Access
    Replies: 4
    Last Post: 11-19-2011, 04:59 PM
  5. Buttons
    By dunnmel4 in forum Access
    Replies: 1
    Last Post: 04-07-2011, 12:27 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