VBA script in Access not working

Monday, July 7, 2014

I have a simply MS Access database (version 2010) with just 4 fields:


Name of DB: Test


test1 = Text


test2 = yes/no (tick boxes)


test3 = Text


test4 = Text


I then created a formular named Form_Test and assigned code to the tick box:



Option Compare Database

Option Explicit

Private Declare Function apiGetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long


Function BenutzerName() As String

Dim lngLen As Long
Dim lngX As Long
Dim strBenutzerName As String

strBenutzerName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strBenutzerName, lngLen)
If lngX <> 0 Then
BenutzerName = Left$(strBenutzerName, lngLen)
Else
BenutzerName = ""
End If

End Function



Private Sub test2_Click()
If test2.Value = True Then
test3 = BenutzerName()
Else
test3 = ""

End If
End Sub


I want to use this code to add the username to the field test3 once the user clicked the tick box in any of the rows. However, the script does not work and I do not understand why. Can anyone help please?







http://ift.tt/1pUlDkZ