Thanks here is the code. Still getting the red font. Is there
something
else that i need to adjust?
Private Sub Command122_Click()
Dim strSQL As String
strSQL = "INSERT INTO tbl_Users (Computer, [Date], [Report], [Users])
"
&_
"VALUES('" & fOSMachineName & "', " & _
Format(Now(), "\#mm\/dd\/yyyy hh\:nn\:ss\#") & _
",'Logout Time', '" & Forms!frm_setup![combo107] & "')"
CurrentDb.Execute strSQL, dbFailOnError
End Sub
:
The Format function is missing a closing quote: that fifth line should
be
Format(Now(), "\#mm\/dd\/yyyy hh\:nn\:ss\#") & _
Sorry about the typo.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Here is what the code looks like:
Private Sub Command122_Click()
Dim strSQL As String
strSQL = "INSERT INTO tbl_Users (Computer, [Date], [Report],
[Users])
" &
_
"VALUES('" & fOSMachineName & "', " & _
Format(Now(), "\#mm\/dd\/yyyy hh\:nn\:ss\#) & _
",'Logout Time', '" & Forms!frm_setup![combo107] & "')"
CurrentDb.Execute strSQL, dbFailOnError
End Sub
:
Rename your Date and Report fields if you can: they're both
reserved
words,
and you should never use reserved words for your own purposes. If
you
cannot
(or will not) rename the fields, ensure you put square brackets
around
them
in SQL statements. (While you're at it, you might want to rename
Users.
While I don't think it's a reserved word, there is a Users
collection
that's
part of Access.) For more on reserved names, see what Allen Browne
has
at
http://www.allenbrowne.com/AppIssueBadWord.html
You added the Users field to the list of fields in the INSERT INTO
statement, but you didn't add a value to put inserted into that
field.
strSQL = "INSERT INTO tbl_Users (Computer, [Date], [Report],
[Users]) "
&
_
"VALUES('" & fOSMachineName & "', " & _
Format(Now(), "\#mm\/dd\/yyyy hh\:nn\:ss\#) & _
",'Logout Time', '" & Forms!frm_setup![combo107] & "')"
CurrentDb.Execute strSQL, dbFailOnError
This assumes that frm_setup is open when you run the code. If it
isn't,
you
need some other way of passing the value for Users.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Sorry for the confusion. So here are the Fields for tbl_Users:
1. Computer - this is the network Id
2. Date - current date and time
3. Report - will be text "Log Out Time"
4. Users - is pulled from a drop down on the form frm_setup
named
combo
107
I already have the module mdlmachinename for the fOSMachineName
call.
When I added the below code to the on click of the button I get
an
error
saying Compile error and the code turns red. If you can help
more
with
the
code I would greatly appreciate it.
Private Sub Command122_Click()
Dim strSQL As String
strSQL = "INSERT INTO tbl_Users (Computer, Date, Report, Users)
" &
_
"VALUES('" & fOSMachineName & "', " & _
Format(Now(), "\#mm\/dd\/yyyy hh\:nn\:ss\#) & _
",'Logout Time')"
CurrentDb.Execute strSQL, dbFailOnError
End Sub
:
Um, you can't have a "table ... with a close database button on
it".
You
must mean a form.
Go to
http://www.mvps.org/access/api/api0009.htm at "The Access
Web"
and
copy that into a new module. (Remember not to name the module
the
same
as
the function)
In the Click event for your close database button, you need code
like:
Dim strSQL As String
strSQL = "INSERT INTO tbl_Users (ComputerName, LogoutTime,
Action) "
&
_
"VALUES('" & fOSMachineName & "', " & _
Format(Now(), "\#mm\/dd\/yyyy hh\:nn\:ss\#) & _
", 'Logout Time')"
CurrentDb.Execute strSQL, dbFailOnError
Note that I had to guess at the names of the fields in your
tbl_User
table.
Change them as appropriate.
Note, too, that the 2nd line of the assignment statement to
strSQL
is,
exagerated for clarity:
" VALUES( ' " & fOSMachineName & " ' , " & _
and those are single quotes on either side of Logout Time on the
4th
line.
Have you applied Access Security to the application and you want
their
Access User Id, or are you looking for their network Id? If you
want
their
network Id, grab
http://www.mvps.org/access/api/api0008.htm and
copy
it
into
a new module as well.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
I have already deleted the code that was giving me the error.
So
I
need
to
start from fresh. I have a main table named tbl_issues with a
close
database
button on it. When the close database button is chosen I want
to
capture
the
date/time, computer name, and text saying "Logout Time" and
send
these
fields
as a new record to my table tbl_Users which has all these
fields.
Can
this
be done? Thanks in advance I recognize your name as one of
the
top
Access
people on the net!
:
How are you currently trying that's failing?
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
message
I want to capture computer name and date/time in a table
when
you
click
database close button on a form. Is this possible? I keep
getting
cant
save
record error.