Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 :

  1. Item ID Check Out : Shows a list of all ItemsIDs and Item Name from tblLibraryItem
  2. Member ID Checked out to : Shows the Member ID, Member First Name and Last Name.

Now There is button to perform following tasks :

  1. If the ItemID in the ItemID combo box is blank, we need to display a message and exit the sub without doing anything else.

  2. If the MemberID in the MemberID combo box is blank, we need to display a message and exit the sub without doing anything else.

  3. 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
222 views
Welcome To Ask or Share your Answers For Others

1 Answer

use the .Value property instead of .Text

then you can throw away the .SetFocus and everything should work :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...