Error 2110

I have this error of 2110 that comes up under the lstAccounts.Setfocus. Im trying to figure out why this is happening. Am i missing something or should I remove something.  There is a lstemployees that has some names, but I have a delete button that should remove the name in the listbox but it is not deleteing anything and is coming up with the erro 2110.  
Private Sub cmdDelete_Click()
    If MsgBox("Are You Sure you want to delete the Employee?", vbOKCancel + vbInformation) <> vbOK Then
      Exit Sub
    End If
 
     
    CurrentDb.Execute ("Delete * From Employees where EmployeeID=" & Me.txtID)
    lstEmployee.Requery
    lstEmployee.SetFocus
    cmdClear.Enabled = False

Open in new window

goingolfn99Asked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
try

    CurrentDb.Execute ("Delete * From Employees where EmployeeID=" & Me.txtID)
    'enable the lstemployee first before the requery
    lstEmployee.Enabled = True

    lstEmployee.Requery
   
    lstEmployee.SetFocus
    cmdClear.Enabled = False
0
 
Rey Obrero (Capricorn1)Commented:

Are you using a subform?

0
 
Rey Obrero (Capricorn1)Commented:
if you are, you need to set the focus to the subform first, then to the control in the subform

from the main form

me.subformName.setfocus

me.subformName.form.controlname.setfocus
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Rey Obrero (Capricorn1)Commented:
also check if the control you want to set the focus is enabled.
if not you have to enable the control first
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
" but I have a delete button that should remove the name in the listbox but it is not deleteing anything "

Should this be:

CurrentDb.Execute ("Delete * From Employees where EmployeeID=" & Me.lstEmployee  

instead of Me.txtID  ?  Isn't the ID value in the list box, maybe column 0 ?

mx
0
 
goingolfn99Author Commented:
Thanks guys, so i was able to get rid of the error of the 2110 but now the deleted item in the listbox does not get updated or requeried. And thus still remains in the listbox.  So describe it a little more its an administration form that adds, changes, deletes any employees. I can either upload the file or you can take a look at the code listed below.


Option Compare Database
 
Private Sub cmdAddNew_Click()
    
    txtName = Null
    txtPosition = Null
    txtLocation = Null
    txtID = 0
    chkNew = True
    '--- enable the text boxes and the Save button
    
    txtID.Enabled = True
    txtName.Enabled = True
    txtPosition.Enabled = True
    txtLocation.Enabled = True
    
    
    
    txtName.SetFocus
    '--- disable the list box, the Add New button, the Close button, and the Edit button
    '--- must be done after the setfocus as we cannot disable something that has focus
    lstEmployee.Enabled = False
    cmdAddNew.Enabled = False
    cmdEdit.Enabled = False
    cmdExit.Enabled = True
    cmdClear.Enabled = True
    cmdSave.Enabled = True
    cmddelete.Enabled = False
 
End Sub
 
Private Sub cmdClear_Click()
    txtName = Null
    txtPosition = Null
    txtLocation = Null
    txtID = 0
    chkNew = False
    
    lstEmployee.Enabled = True
    cmdAddNew.Enabled = True
    cmdExit.Enabled = True
  
    lstEmployee.SetFocus
    lstEmployee = lstEmployee.ItemData(0)
    Call lstEmployee_AfterUpdate
  
    
    txtName.Enabled = False
    txtPosition.Enabled = False
    txtLocation.Enabled = False
    txtID.Enabled = False
    
    cmdSave.Enabled = False
    cmdEdit.Enabled = True
    cmdClear.Enabled = False
    cmddelete.Enabled = False
End Sub
 
Private Sub cmdDelete_Click()
    If MsgBox("Are You Sure you want to delete the Employee?", vbOKCancel + vbInformation) <> vbOK Then
      Exit Sub
    End If
 
     
    CurrentDb.Execute ("Delete * From Employees where EmployeeID=" & Me.txtID)
    lstEmployee.Requery
    lstEmployee.Enabled = True
    lstEmployee.SetFocus
    cmdClear.Enabled = False
 
End Sub
 
Private Sub cmdEdit_Click()
    If lstEmployee.ItemsSelected.Count <> 1 Then Exit Sub
    
    txtID.Enabled = True
    txtName.Enabled = True
    txtPosition.Enabled = True
    txtLocation.Enabled = True
    
    txtName.SetFocus
    
    lstEmployee.Enabled = False
    
    cmdSave.Enabled = True
    cmdAddNew.Enabled = False
    cmdExit.Enabled = False
    cmdEdit.Enabled = False
    cmdClear.Enabled = True
    cmddelete.Enabled = True
        
End Sub
Private Sub cmdExit_Click()
    DoCmd.Close
End Sub
 
Private Sub cmdSave_Click()
If IsNull(txtName) Then
        MsgBox "Need a Employee Name"
        txtName.SetFocus
        Exit Sub
    End If
    
    Dim rst As Recordset
    Set rst = CurrentDb.OpenRecordset("select * from Employees where EmployeeID=" & txtID)
    
    If chkNew = True Then
        rst.AddNew
    Else
        rst.Edit
    End If
    
    rst!Name = txtName
    rst!Title = txtPosition
    rst!Site = txtLocation
    rst.Update
    rst.Close
    
    Set rst = Nothing
    chkNew = False
    
    lstEmployee.Enabled = True
    cmdAddNew.Enabled = True
    cmdExit.Enabled = True
    
    lstEmployee.Requery
    lstEmployee.SetFocus
    lstEmployee = lstEmployee.ItemData(0)
    Call lstEmployee_AfterUpdate
   
    txtID.Enabled = False
    txtName.Enabled = False
    txtPosition.Enabled = False
    txtLocation.Enabled = False
    
    cmdSave.Enabled = False
    cmdEdit.Enabled = True
    cmdClear.Enabled = False
    cmddelete.Enabled = False
End Sub
Private Sub Form_Open(Cancel As Integer)
    lstEmployee.SetFocus
    lstEmployee = lstEmployee.ItemData(0)
    Call lstEmployee_AfterUpdate
End Sub
Private Sub lstEmployee_AfterUpdate()
    txtID = lstEmployee.Column(0)
    txtName = lstEmployee.Column(1)
    txtPosition = lstEmployee.Column(2)
    txtLocation = lstEmployee.Column(3)
    cmddelete.Enabled = True
End Sub

Open in new window

0
 
goingolfn99Author Commented:
Nope, stil not working. the employees is still requering  the listbox that I want to delete.  Even if I remove the lstEmployee.SetFocus it doesn't change at all. I have a simple query, is there something wrong it, the query is coming off one table so it shouldn't be too complicated. here is my SQL
SELECT DISTINCT [Employees].[EmployeeID], [Employees].[Name], [Employees].[Title], [Employees].[Site] FROM Employees WHERE ((([Employees].[Name]) Is Not Null)); 

Open in new window

0
 
goingolfn99Author Commented:
yes, the listbox that i want setfocus is enabled.
0
 
Rey Obrero (Capricorn1)Commented:
is employeeId a number type of data?



is Me.txtID the same as the employeeID?
0
 
Rey Obrero (Capricorn1)Commented:
better that you upload the zip db here www.ee-stuff.com
0
 
goingolfn99Author Commented:
NO WORRIES, I STARTED FROM SCRATCH AND REAPPLIED THE CODE AND THE TABLE SETTINGS AND EVERYTHING. AS USUAL ACCESS WITH ITS LITTLE QUIRKS MAKES MY LIFE A LIVING HELL.
0
 
goingolfn99Author Commented:
THANKS GUYS FOR THE EFFORT AND QUICK RESPONSE
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.