Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate history table automatically?

Status
Not open for further replies.

snowyej

Technical User
Nov 26, 2001
69
US
Hi!

I have a form that has a button on it that, when clicked, pops up an Outlook email form. The user hits send to send an email to a select group of people. The email part works fine.

What I'd also like this button to do is add a line of text to a field in another table that just says "email sent" or something like that and the current date. This table is basically a history table. I'd like to be able to do this automatically without having the user do anything.

Here's the piece of code I have so far, but I'm sure it's even close to what I need. I'm still fairly new with the coding side of Access. :)


'add history
DoCmd.OpenForm "frmHistory", acNormal, , , acFormAdd, acHidden
DoCmd.GoToRecord acDataForm, "frmHistory", acNewRec
Forms![frmHistory].[Date] = Date
Forms![frmHistory].[History] = "Email sent."


Hopefully this makes sense? Let me know if I need to clarify anything.

Thanks much!
Elizabeth :)
 
This is more easily done using DAOs. Put the following code in the click event.
Dim db as database
Dim rs as recordset
Set db = currentdb()
Set rs =db.openrecordset("Tablename")

rs.addnew
rs.Fields("fieldname1") = ?????
etc
etc
rs.update
rs.close
 
You know what? I actually had it working just missed one little thing. On my form I have a history button, when you click on it, it shows the history for that particular record (where HistoryID = FormID). I had forgotten to put a line in the code that would set the HistoryID equal to the FormID. Once I did that, my code worked, as did yours.

Thanks for your help!

Elizabeth :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top