Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2009
    Posts
    23

    Unanswered: Adding save button in form

    Hi All,

    I would like to add a save button to my current form. The record should be saved when the save button is pressed. What is the VBA routine which i need to use for the button to perform this task. Can any one of you please let me know. Thanks a lot.

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Is your form bound to Access tables? SQL Server? Linked tables? I don't believe you have provided enough information to answer this adequately.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    If your current form is "bound" to a table/query and you haven't put in any special type coding, MSAccess will save the data as it's entered (unless something happens with the connection to the tables.) You don't really need a save button but you could write a routine to cancel/delete the record unless the save button is pushed (I will sometimes rename my Close button which simply closes the form as Save as the user felt more comfortable with this wording).

    If you're using "unbound" forms (ideal for a Save button), you need to write code when the Save button is pushed to save the data from the form to the table. The code you use to connect to the tables for saving depends on how you have it set up.
    Last edited by pkstormy; 06-03-09 at 00:01.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Jun 2009
    Posts
    23
    My form is bound to MS Access tables. I want to add an extra save button just to keep user friendly.

    You have mentioned that "we can write a routine to cancel/delete the record unless the save button is pushed". how can we do this..mean how can we know that save button is not pressed.

    Also which routine do i need to use in VB code to save the record (m assuming that the routine should be called inside like saveButton_onClick).

    Please let me know.

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Behind the command button, just add the following code:

    On Error Resume Next
    DoCmd****nCommand accmdSaveRecord
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    *sigh*

    Docmd<DOT>RunCommand accmdSaveRecord
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    This site is very loosely controlling site links to Russia... very loosely.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Apr 2009
    Posts
    85
    'This might work

    Dim strMsg As String, strTitle As String

    strMsg = "Do You Want To Save This Record?"
    strTitle = " Save Record ?"

    If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then
    Me.Undo

    End If

    DoCmd.GoToRecord , , acNewRec

  9. #9
    Join Date
    Oct 2008
    Posts
    9
    This is exactly what i need. I appreciate all for their help.

  10. #10
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    ^^ Which one was exactly what you needed? lol
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  11. #11
    Join Date
    Oct 2008
    Posts
    9
    The second suggestion given by Timothyl.

  12. #12
    Join Date
    Jun 2011
    Posts
    2

    Adding that code to beforeupdate event?

    Hello, I also found Timothyl's suggestion to be exactly what I need however I do not really know how to implement it, also I currently have a macro that runs on the beforeupdate event. Would the code even go in the beforeupdate event?

    any help you could provide me would be greatly appreciated.

    thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •