我正在尝试为变量分配一个列表框值,但是每次运行代码时都会得到无效的Null错误。
Private Sub CmdEnter_Click()
Dim RS As dao.Recordset
Dim RS2 As dao.Recordset2
Dim FirstName As String
Dim Lastname As String
Dim I As Integer
Dim Department As String
FirstName = TxtFirstName.Value
Lastname = TxtLastName.Value
With LstDepartment
For I = 0 To LstDepartment.ColumnCount
Department = LstDepartment.Column(I)
Next I
MsgBox Department
End With
'Set RS = CurrentDb.OpenRecordset(DBO_UserNamesTbl)
Set RS = db.OpenRecordset("INSERT INTO DBO_UserNamesTbl (UserNo, FirstName, LastName, Department) VALUES (1, Firstname, lastname, department)")
'RS.Execute "INSERT INTO DBO_UserNamesTbl (UserNo, FirstName, LastName, Department) VALUES (1, Firstname, lastname, department)"
Set RS = db.closerecordset(DBO_UserNamesTbl)
End Sub
列表框从已创建的名为departments的表中获取信息,它显示并允许我选择没有问题的值。
答案 0 :(得分:0)
您需要访问ListBox的“List”属性才能访问其值。您能否发布用于填充列表框的代码?然后我可以为您提供有关如何访问它的更多详细信息。