Troubleshooting Logging module

R

requeth

Hello everyone,

I have the following code that is supposed to grab the Novell user ID,
the date, and save it into a table as a logfile.

Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function GetUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = ""
End If
v_user = GetUserName
sqlInsertStatement = "Insert into UserLog([UserName],[LoginTime])
Values(" & v_user & ",'" & Date & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
End Function

I set this as a module and then call it with a macro. When I run the
code a box pops up labeled "Enter Parameter Value" then the read only
Novell user ID, and a text box. If you ever information into the text
box and hit ok, that's saved as the user ID, if you do not, nothing is
saved except the date. I'm very rusty at VB, and to be honest did a
script kiddie hack job of a few scripts to get the above working (my
code keeled). Anyone see where I'm messing up?

Thanks!
 
D

Douglas J. Steele

Since the User Name is text, you need to have quotes around it. Assuming
LoginTime is a Date field, you need to have # delimiters, not quotes (and
the dates need to be in mm/dd/yyyy format, regardless of what the Short Date
format may have been set to in Regional Settings)

sqlInsertStatement = "Insert into UserLog([UserName],[LoginTime]) " & _
"Values('" & v_user & "'," & Format(Date, "\#mm\/dd\/yyyy\#") & ")"

(if LoginTime is text, ignore the second change)
 
R

requeth

Thank you Mr. Wizzard!!!
Since the User Name is text, you need to have quotes around it. Assuming
LoginTime is a Date field, you need to have # delimiters, not quotes (and
the dates need to be in mm/dd/yyyy format, regardless of what the Short Date
format may have been set to in Regional Settings)

sqlInsertStatement = "Insert into UserLog([UserName],[LoginTime]) " & _
"Values('" & v_user & "'," & Format(Date, "\#mm\/dd\/yyyy\#") & ")"

(if LoginTime is text, ignore the second change)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hello everyone,

I have the following code that is supposed to grab the Novell user ID,
the date, and save it into a table as a logfile.

Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function GetUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = ""
End If
v_user = GetUserName
sqlInsertStatement = "Insert into UserLog([UserName],[LoginTime])
Values(" & v_user & ",'" & Date & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
End Function

I set this as a module and then call it with a macro. When I run the
code a box pops up labeled "Enter Parameter Value" then the read only
Novell user ID, and a text box. If you ever information into the text
box and hit ok, that's saved as the user ID, if you do not, nothing is
saved except the date. I'm very rusty at VB, and to be honest did a
script kiddie hack job of a few scripts to get the above working (my
code keeled). Anyone see where I'm messing up?

Thanks!
 

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

Top