0

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?

3
  • 1
    Try putting breakpoints in your code and see at which line of code the error occurs. That might help isolate the cause of the problem. Commented Jul 7, 2014 at 12:59
  • When you say "Does not work", it doesn't help anyone else solve your question either, unless the error is blatantly obvious. What didn't it do? Commented Jul 7, 2014 at 13:16
  • If your problem is "I don't see anything happening", start with a breakpoint on the line If test2.Value = True Then to make sure your click event is triggering at all. Then check the value of test2.Value to verify it's what you expect. Commented Jul 7, 2014 at 13:31

1 Answer 1

1

Make sure your code is in right place,

In the Design mode of the form

Right click the Check box and select Properties -> Event Tab->On Click->Code Builder will open the code editor

That's where your on code must reside

Edit:

In addition, Follow this link to set Breakpoint(F9) in your code to see if your code is being triggered , the link also contains information about debugging.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.