PC Review


Reply
Thread Tools Rate Thread

Capture Name and Date

 
 
=?Utf-8?B?S2V2aW43Ng==?=
Guest
Posts: n/a
 
      9th Oct 2006
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.
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      10th Oct 2006
How are you currently trying that's failing?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Kevin76" <(E-Mail Removed)> wrote in message
news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
>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.



 
Reply With Quote
 
=?Utf-8?B?S2V2aW43Ng==?=
Guest
Posts: n/a
 
      10th Oct 2006
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!

"Douglas J. Steele" wrote:

> How are you currently trying that's failing?
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "Kevin76" <(E-Mail Removed)> wrote in message
> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
> >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.

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      10th Oct 2006
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
http://I.Am/DougSteele
(no e-mails, please!)


"Kevin76" <(E-Mail Removed)> wrote in message
news:67C7D67A-A0C5-4257-BB0E-(E-Mail Removed)...
>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!
>
> "Douglas J. Steele" wrote:
>
>> How are you currently trying that's failing?
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no private e-mails, please)
>>
>>
>> "Kevin76" <(E-Mail Removed)> wrote in message
>> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
>> >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.

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?S2V2aW43Ng==?=
Guest
Posts: n/a
 
      10th Oct 2006
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

"Douglas J. Steele" wrote:

> 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
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Kevin76" <(E-Mail Removed)> wrote in message
> news:67C7D67A-A0C5-4257-BB0E-(E-Mail Removed)...
> >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!
> >
> > "Douglas J. Steele" wrote:
> >
> >> How are you currently trying that's failing?
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no private e-mails, please)
> >>
> >>
> >> "Kevin76" <(E-Mail Removed)> wrote in message
> >> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
> >> >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.
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      10th Oct 2006
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/Ap****ueBadWord.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
http://I.Am/DougSteele
(no e-mails, please!)


"Kevin76" <(E-Mail Removed)> wrote in message
news:5FD9D44E-F75D-480A-8F6D-(E-Mail Removed)...
> 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
>
> "Douglas J. Steele" wrote:
>
>> 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
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Kevin76" <(E-Mail Removed)> wrote in message
>> news:67C7D67A-A0C5-4257-BB0E-(E-Mail Removed)...
>> >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!
>> >
>> > "Douglas J. Steele" wrote:
>> >
>> >> How are you currently trying that's failing?
>> >>
>> >> --
>> >> Doug Steele, Microsoft Access MVP
>> >> http://I.Am/DougSteele
>> >> (no private e-mails, please)
>> >>
>> >>
>> >> "Kevin76" <(E-Mail Removed)> wrote in message
>> >> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
>> >> >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.
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?S2V2aW43Ng==?=
Guest
Posts: n/a
 
      10th Oct 2006
Ok used this new code you provided and I get all red text. Was I supposed to
change something?

"Douglas J. Steele" wrote:

> 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/Ap****ueBadWord.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
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Kevin76" <(E-Mail Removed)> wrote in message
> news:5FD9D44E-F75D-480A-8F6D-(E-Mail Removed)...
> > 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
> >
> > "Douglas J. Steele" wrote:
> >
> >> 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
> >> http://I.Am/DougSteele
> >> (no e-mails, please!)
> >>
> >>
> >> "Kevin76" <(E-Mail Removed)> wrote in message
> >> news:67C7D67A-A0C5-4257-BB0E-(E-Mail Removed)...
> >> >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!
> >> >
> >> > "Douglas J. Steele" wrote:
> >> >
> >> >> How are you currently trying that's failing?
> >> >>
> >> >> --
> >> >> Doug Steele, Microsoft Access MVP
> >> >> http://I.Am/DougSteele
> >> >> (no private e-mails, please)
> >> >>
> >> >>
> >> >> "Kevin76" <(E-Mail Removed)> wrote in message
> >> >> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
> >> >> >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.
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?S2V2aW43Ng==?=
Guest
Posts: n/a
 
      10th Oct 2006
Users field should come from the form that is still open and field
Forms!frm_setup![combo107]

"Douglas J. Steele" wrote:

> 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/Ap****ueBadWord.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
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Kevin76" <(E-Mail Removed)> wrote in message
> news:5FD9D44E-F75D-480A-8F6D-(E-Mail Removed)...
> > 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
> >
> > "Douglas J. Steele" wrote:
> >
> >> 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
> >> http://I.Am/DougSteele
> >> (no e-mails, please!)
> >>
> >>
> >> "Kevin76" <(E-Mail Removed)> wrote in message
> >> news:67C7D67A-A0C5-4257-BB0E-(E-Mail Removed)...
> >> >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!
> >> >
> >> > "Douglas J. Steele" wrote:
> >> >
> >> >> How are you currently trying that's failing?
> >> >>
> >> >> --
> >> >> Doug Steele, Microsoft Access MVP
> >> >> http://I.Am/DougSteele
> >> >> (no private e-mails, please)
> >> >>
> >> >>
> >> >> "Kevin76" <(E-Mail Removed)> wrote in message
> >> >> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
> >> >> >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.
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?S2V2aW43Ng==?=
Guest
Posts: n/a
 
      10th Oct 2006
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" wrote:

> 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/Ap****ueBadWord.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
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Kevin76" <(E-Mail Removed)> wrote in message
> news:5FD9D44E-F75D-480A-8F6D-(E-Mail Removed)...
> > 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
> >
> > "Douglas J. Steele" wrote:
> >
> >> 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
> >> http://I.Am/DougSteele
> >> (no e-mails, please!)
> >>
> >>
> >> "Kevin76" <(E-Mail Removed)> wrote in message
> >> news:67C7D67A-A0C5-4257-BB0E-(E-Mail Removed)...
> >> >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!
> >> >
> >> > "Douglas J. Steele" wrote:
> >> >
> >> >> How are you currently trying that's failing?
> >> >>
> >> >> --
> >> >> Doug Steele, Microsoft Access MVP
> >> >> http://I.Am/DougSteele
> >> >> (no private e-mails, please)
> >> >>
> >> >>
> >> >> "Kevin76" <(E-Mail Removed)> wrote in message
> >> >> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
> >> >> >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.
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      10th Oct 2006
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
http://I.Am/DougSteele
(no e-mails, please!)


"Kevin76" <(E-Mail Removed)> wrote in message
news:598A95C1-DFD5-4BA6-A8D9-(E-Mail Removed)...
> 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" wrote:
>
>> 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/Ap****ueBadWord.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
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Kevin76" <(E-Mail Removed)> wrote in message
>> news:5FD9D44E-F75D-480A-8F6D-(E-Mail Removed)...
>> > 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
>> >
>> > "Douglas J. Steele" wrote:
>> >
>> >> 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
>> >> http://I.Am/DougSteele
>> >> (no e-mails, please!)
>> >>
>> >>
>> >> "Kevin76" <(E-Mail Removed)> wrote in message
>> >> news:67C7D67A-A0C5-4257-BB0E-(E-Mail Removed)...
>> >> >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!
>> >> >
>> >> > "Douglas J. Steele" wrote:
>> >> >
>> >> >> How are you currently trying that's failing?
>> >> >>
>> >> >> --
>> >> >> Doug Steele, Microsoft Access MVP
>> >> >> http://I.Am/DougSteele
>> >> >> (no private e-mails, please)
>> >> >>
>> >> >>
>> >> >> "Kevin76" <(E-Mail Removed)> wrote in message
>> >> >> news:B899FB85-9D33-4F51-892E-(E-Mail Removed)...
>> >> >> >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.
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I capture a date? Capture a variable date & use with text Microsoft Excel Misc 3 27th Nov 2008 02:40 AM
How do I capture just the date from date/time field in an SQL Dat =?Utf-8?B?ZWh1ZHNvbg==?= Microsoft Access VBA Modules 1 16th Feb 2006 02:14 PM
How do I capture just the date from date/time field in an SQL Dat. =?Utf-8?B?ZWh1ZHNvbg==?= Microsoft Access Queries 1 15th Feb 2006 04:14 PM
want to capture date elegantpartner Microsoft Excel Misc 1 9th Jan 2006 04:20 AM
Capture of First Use Date Tony Uythoven Microsoft Access Forms 5 15th Feb 2005 11:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:59 PM.