By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,455 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,455 IT Pros & Developers. It's quick & easy.

onclick event

P: 65
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
Jul 10 '06 #1
Share this Question
Share on Google+
5 Replies


100+
P: 179
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
Jul 10 '06 #2

P: 65
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
Jul 10 '06 #3

100+
P: 179
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
Jul 12 '06 #4

P: 65
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?
Jul 12 '06 #5

P: 65
found this one out, too:

i added
Forms!frm_timesheet.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
Jul 12 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.