R
Ronny
Hi.
I am trying to insert a variable (apGetUserName)from a
function into the database; the WordDoc and Now variable
goes well. I am able to put the variable on a MsgBox and
forms, but not in the table. I have also tried to put
apGetUserName in the SQL and several "" '' && types.
Does anybody know why or has anybody a solution?
---------------------------------
Option Compare Database
Option Explicit
'-- API Calls for getting the current user and computer
names
Declare Function wu_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As
Long) _
As Long
------------------------------------------
Function ap_GetUserName() As Variant
Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long
'-- Set up the buffer
strUserName = String$(255, 0)
lngLength = 255
'-- Make the call
lngResult = wu_GetUserName(strUserName, lngLength)
'-- Assign the value
ap_GetUserName = strUserName
End Function
-------------------------------------------
Dim sqlPers As String
Dim dbs As ADODB.Connection
Dim user As String
user = ap_GetUserName
Set dbs = Application.CurrentProject.Connection
sqlPers = "INSERT INTO Historikk VALUES ('" & WordDoc
& "', Now(), '" & user & "')"
dbs.Execute sqlPers
dbs.Close
I am trying to insert a variable (apGetUserName)from a
function into the database; the WordDoc and Now variable
goes well. I am able to put the variable on a MsgBox and
forms, but not in the table. I have also tried to put
apGetUserName in the SQL and several "" '' && types.
Does anybody know why or has anybody a solution?
---------------------------------
Option Compare Database
Option Explicit
'-- API Calls for getting the current user and computer
names
Declare Function wu_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As
Long) _
As Long
------------------------------------------
Function ap_GetUserName() As Variant
Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long
'-- Set up the buffer
strUserName = String$(255, 0)
lngLength = 255
'-- Make the call
lngResult = wu_GetUserName(strUserName, lngLength)
'-- Assign the value
ap_GetUserName = strUserName
End Function
-------------------------------------------
Dim sqlPers As String
Dim dbs As ADODB.Connection
Dim user As String
user = ap_GetUserName
Set dbs = Application.CurrentProject.Connection
sqlPers = "INSERT INTO Historikk VALUES ('" & WordDoc
& "', Now(), '" & user & "')"
dbs.Execute sqlPers
dbs.Close