I am having these table :
tblLibraryItem : ItemID , MediaType , ItemName , DateAcquire , Status , CheckedOut , DueDate
tblMember : MemberID , FirstName , LastName , Email , Phone , DateBecameMember
There is checkout form, having two drop down :
- Item ID Check Out : Shows a list of all ItemsIDs and Item Name from tblLibraryItem
- Member ID Checked out to : Shows the Member ID, Member First Name and Last Name.
Now There is button to perform following tasks :
If the ItemID in the ItemID combo box is blank, we need to display a message and exit the sub without doing anything else.
If the MemberID in the MemberID combo box is blank, we need to display a message and exit the sub without doing anything else.
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.
Here is my code :
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
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
Updating table gives error now :
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
It gives error that too few parameters in Execute statement. Please help to correct it
See Question&Answers more detail:os