Capture Name and Date

G

Guest

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.
 
G

Guest

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!
 
D

Douglas J. Steele

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.
 
G

Guest

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
 
D

Douglas J. Steele

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.
 
G

Guest

Ok used this new code you provided and I get all red text. Was I supposed to
change something?

Douglas J. Steele said:
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!)


Kevin76 said:
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
 
G

Guest

Users field should come from the form that is still open and field
Forms!frm_setup![combo107]

Douglas J. Steele said:
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!)


Kevin76 said:
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
 
G

Guest

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




Douglas J. Steele said:
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!)


Kevin76 said:
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
 
D

Douglas J. Steele

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!)


Kevin76 said:
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




Douglas J. Steele said:
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!)


Kevin76 said:
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)


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.
 
G

Guest

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

Douglas J. Steele said:
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!)


Kevin76 said:
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




Douglas J. Steele said:
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)


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.
 
D

Douglas J. Steele

It looks as though you're missing the space between the ampersand and the
underscore in the first line of assignment (the 3rd line).

If that doesn't solve it, which line is red?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Kevin76 said:
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

Douglas J. Steele said:
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!)


Kevin76 said:
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)


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.
 
G

Guest

That worked like a charm!! Thank you. Now what do I put in the code to
close the database completely as this button is menat to close the db as well.

Douglas J. Steele said:
It looks as though you're missing the space between the ampersand and the
underscore in the first line of assignment (the 3rd line).

If that doesn't solve it, which line is red?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Kevin76 said:
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

Douglas J. Steele said:
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)


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.
 
D

Douglas J. Steele

Application.Quit

will shut down Access.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Kevin76 said:
That worked like a charm!! Thank you. Now what do I put in the code to
close the database completely as this button is menat to close the db as
well.

Douglas J. Steele said:
It looks as though you're missing the space between the ampersand and the
underscore in the first line of assignment (the 3rd line).

If that doesn't solve it, which line is red?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Kevin76 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top