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