onclick event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mpmason14
    New Member
    • Jun 2006
    • 65

    #1

    onclick event

    i have a form to add new employees to...i want to be able to click ONE button and have it save the data,update the database, and close the form all at once.

    any ideas how to do this?
    i have the button for saving it, just not sure how to add the other two parts yet
  • comteck
    New Member
    • Jun 2006
    • 179

    #2
    You said you want to save and update at the same time. If you have a form set up with a Record Source pointing to the table you want to save to, then it will save this data as you are typing it in. When you exit the form, the data should be in the next record of the table.

    When you talk about updating a table, it means that existing data is going to be changed. If this is what you want to do, then you have to use an Update Query. You then open that query when you need it by adding the following code to a button on your form:

    Private Sub btnUpdate_Click ()
    DoCmd.OpenQuery ("queryname" )
    End Sub

    Let me know if it's existing data you want to change in the table, or if it's simply adding data to the table because creating an update query is a little more complex than a normal query.. however it's not overly difficult.

    To close the form, use:
    DoCmd.Close

    The overall code would be:

    Private Sub btnUpdate_Click ()
    DoCmd.OpenQuery ("queryname" )
    DoCmd.Close
    End Sub

    Have you ever looked at some of the online tutorials for MS Access? There are some great ones out there.

    Hope this helps.
    comteck

    Comment

    • mpmason14
      New Member
      • Jun 2006
      • 65

      #3
      i want to update the form so it shows the new record while browsing after i close the form that adds the employee.
      i hope this is making sense
      im going to check the access tutorials also

      Comment

      • comteck
        New Member
        • Jun 2006
        • 179

        #4
        I'm sorry. I'm afraid it's not making sense. Maybe somebody else can shed some light here.

        It sounds like you're saying you want to update a form after the form has been closed. A form is just an interface for data that stored in a database. After the form closes, the data is lost from the form. Are you sure it's not a table that you want updated.

        And if it is a table, I still don't quite get what it is you want to do.

        comteck

        Comment

        • mpmason14
          New Member
          • Jun 2006
          • 65

          #5
          i understand that the table is the underlying data source, and that is what is being updated. but i want the form to show the updated information without having to close the form and reopen it. is there a way to do this?

          Comment

          • mpmason14
            New Member
            • Jun 2006
            • 65

            #6
            found this one out, too:

            i added
            Forms!frm_times heet.Requery
            to my close button on my form and whenever i close the form, it does exactly what it is suppossed to do...close the second form and requery (v. refresh!) the database and updates the form.

            thanks to all of you with the ideas. hope this helps anyone who is looking for the same thing i was

            Comment

            Working...