我有这些表:
tblLibraryItem:ItemID,MediaType,ItemName,DateAcquire,Status,CheckedOut,DueDate
tblMember:MemberID,FirstName,LastName,Email,Phone,DateBecameMember
有结帐表格,有两个下拉:
现在有按钮可以执行以下任务:
如果ItemID组合框中的ItemID为空,我们需要显示一条消息并退出该子而不做其他任何事情。
如果MemberID组合框中的MemberID为空,我们需要显示一条消息并退出该子消息而不做其他任何操作。
对于所选的ItemID,请检查项目的状态。如果状态为“已检出”,则显示该项已被检出的消息,并退出该子而不执行任何其他操作。
这是我的代码:
Dim ItemName As String
Dim MemberID As String
Dim LastName As String
Dim FirstName As String
Dim currDatabase As DAO.Database
Set currDatabase = CurrentDb
Dim rstLibraryItem As DAO.Recordset
Set rstLibraryItem = currDatabase.OpenRecordset("tblLibraryItem")
rstLibraryItem.MoveFirst
Do While Not rstLibraryItem.EOF
If rstLibraryItem("ItemID") = CheckedOut Then Exit Do
rstLibraryItem.MoveNext
Loop
cboItemIDCheckOut.SetFocus
ItemID = cboItemIDCheckOut.Text
cboMemberIDCheckedOutTo.SetFocus
MemberID = cboMemberIDCheckedOutTo.Text
If cboItemIDCheckOut.Text = "" Then
MsgBox "Please select or type an ItemID"
Exit Sub
End If
If cboMemberIDCheckedOutTo.Text = "" Then
MsgBox "Please select or type an MemberID"
Exit Sub
End If
If cboItemIDCheckOut.ItemID = "Checked Out" Then
MsgBox "That item is already checked out"
Exit Sub
End If
但是当我点击按钮时,我得到运行时错误2185的错误。除非控件具有焦点,否则不能引用控件的属性或方法。
我做错了吗?请帮忙
更新表现在出错:
Dim checkOuString As String
checkOuString = "Checked"
Dim updatLibItemSQL As String
updatLibItemSQL = "UPDATE [tblLibraryItem]"
updatLibItemSQL = updatLibItemSQL & " SET [Status] = [checkOuString] "
updatLibItemSQL = updatLibItemSQL & " WHERE [ItemID] = [selectItemID] "
currDatabase.Execute updatLibItemSQL, dbFailOnError
它给出错误,即Execute语句中的参数太少。请帮忙纠正它
答案 0 :(得分:0)
使用.Value属性而不是.Text
然后你可以扔掉.SetFocus,一切都应该工作:)