【发布时间】:2014-07-07 23:14:42
【问题描述】:
我有一个简单的 MS Access 数据库(2010 版),只有 4 个字段:
数据库名称:测试
test1 = 文本
test2 = 是/否(勾选框)
test3 = 文本
test4 = 文本
然后我创建了一个名为 Form_Test 的公式并将代码分配给复选框:
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
一旦用户单击任何行中的复选框,我想使用此代码将用户名添加到字段 test3。但是,脚本不起作用,我不明白为什么。有人可以帮忙吗?
【问题讨论】:
-
尝试在代码中放置断点,看看错误发生在哪一行代码。这可能有助于找出问题的原因。
-
当您说 “不起作用” 时,它也无助于其他任何人解决您的问题,除非错误非常明显。它没有做什么?
-
如果您的问题是“我没有看到任何事情发生”,请从
If test2.Value = True Then行上的断点开始,以确保您的点击事件完全触发。然后检查 test2.Value 的值以验证它是否符合您的预期。