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

Capture a Users Name at Startup? 1

Status
Not open for further replies.

Cleis

Technical User
Jun 4, 2000
197
0
0
US
Hi Group:

I would like to be able to capture a users name and date that they enter into a database. I have a table to capture this info. How do I paste this data into the table using code in a module called basStartup?


Thanks;

Rich
Chicago
 
how about something like this:

Code:
With Tablename
   .MoveLast
   .Addnew
   !UserName = Inputbox("Enter your name:","Input required")
   strUserName = !UserName
   If !UserName = "" then
       Do something ....
   End If
   !Date = Inputbox("Enter Date:","Input required")
   strDate = !Date
   If !Date = "" then
       Do something ....
   End If
   .Update
End With
 
Hi, Rich!

You can use usernames which is saved in your workgroup (.MDW) file e.g.:

MyUserTable
AccessID
- long, primary key
UserName - text
AccessTime - Date/Time


Private sub Form_Load() 'Start up form
dim rst as recordset
dim lngAccessID as long

if dcount("AccessID", "MyUserTable")=0 then
lngAccessID = 1
else
lngAccessID = dmax("AccessID", "MyUserTable")+1
end if

set rst=currentdb.openrecordset("Select * From MyUserTable;")
rst.addnew
rst!AccessID=lngAccessID
rst!UserName=CurrentUser 'Function CurrentUser return current user name
rst!AccessTime=now()
rst.update
rst.close
set rst=nothing
end sub

I hope these would give you any idea.

Aivars
 
'Create table "UserLogins" with 2 fields (User, UserDateIn)
'Place this code in the 'Form Open' event


Dim db As Database
Dim rs As Recordset

Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset("UserLogIns")
With rs
.AddNew
!User = Environ("username")
!UserDateIn = Now()
.Update
.Close
End With
Set rs = Nothing
Set db = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top