按钮单击事件未按预期执行任务 [英] Button click event not doing task as expected
问题描述
我有这些桌子:
tblLibraryItem:ItemID,MediaType,ItemName,DateAcquire,Status,CheckedOut,DueDate
tblLibraryItem : ItemID , MediaType , ItemName , DateAcquire , Status , CheckedOut , DueDate
tblMember:MemberID,FirstName,LastName,Email,Phone,DateBecameMember
tblMember : MemberID , FirstName , LastName , Email , Phone , DateBecameMember
有一个结帐表格,其中有两个下拉菜单:
There is checkout form, having two drop down :
- 商品ID检出:显示tblLibraryItem中所有商品ID和商品名称的列表
- 会员ID检出到:显示会员ID,会员的名字和姓氏.
现在有执行以下任务的按钮:
Now There is button to perform following tasks :
-
如果ItemID组合框中的ItemID为空白,则我们需要显示一条消息并退出该子项,而无需执行其他任何操作.
If the ItemID in the ItemID combo box is blank, we need to display a message and exit the sub without doing anything else.
如果"MemberID"组合框中的MemberID为空白,则我们需要显示一条消息并退出该子项,而无需执行其他任何操作.
If the MemberID in the MemberID combo box is blank, we need to display a message and exit the sub without doing anything else.
对于选定的ItemID,检查项目的状态.如果状态为已签出",则显示一条消息,表明该项目已被签出并退出子菜单.
For the ItemID selected, check the status of the Item. If the status is "Checked Out", display a message that the item is already checked out and exit the sub without doing anything else.
这是我的代码:
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的错误.除非控件具有焦点,否则无法引用控件的属性或方法.
But when I click on button I get error that Run time error 2185. You can't reference a property or method for a control unless control has the focus.
我做错什么了吗?请帮助
Am i doing something wrong ? Please help
更新表现在出现错误:
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语句中的参数太少.请帮助纠正它
It gives error that too few parameters in Execute statement. Please help to correct it
推荐答案
使用.Value属性而不是.Text
use the .Value property instead of .Text
然后您可以扔掉.SetFocus,一切都应该正常进行:)
then you can throw away the .SetFocus and everything should work :)
这篇关于按钮单击事件未按预期执行任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!