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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Noob question on adding record 1

Status
Not open for further replies.

pavewayammo

Programmer
Feb 12, 2003
53
US
Ok I want to have a new record added everytime the database is opened to a table with computername, username and date. I understand how to get the comptername, and username but not sure how to have it added to a record.[flush]

Thanks,
paveway [spineyes]
 
Hi!

You can use the following code:

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("YourTable", dbOpenDynaset)

With rst
.AddNew
!fldComputerName = YourComputerName
!fldUserName = YourUserName
!fldDate = Date()
.Update
End With

Set rst = Nothing

If you have a form that opens when the Db opens then just add this code to the open event of the form. This is the easiest method but, if you do not have and do not want such a form, then put the code in a public function (yes function is absolutely necessary) and create a macro called autoexec. Use the RunCode action and in the Function Name box put the name of your public function.

hth


Jeff Bridgham
bridgham@purdue.edu
 
[thumbsup2] Cool it works to a point. May because of the network or maybe I did something wrong. Right now all I get is the date with out the time and it is set to General Date for the format. I don't get anything in the ComputerName or UserName field. This DB is ran on a Windows 2000 network. Any way or where I can just type something in to see if ComputerName and UserName work right on this network?

Any ideas?

paveway [machinegun]
 
I found this "echo %computername%" in another forum and it works. Still have the first problem.


paveway [machinegun]
 
Hi!

If you want the time as well use Now() instead of Date(). What functions are you using to get the computer name and UserName?

hth


Jeff Bridgham
bridgham@purdue.edu
 
Well I figured it out. I forgot Environ. Added that and now it works.

BTW I gave you a star jebry. Thank you for the help.[2thumbsup]


paveway [machinegun]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top