Solved

Error 2110

Posted on 2007-11-27
12
389 Views
Last Modified: 2013-11-28
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

0
Comment
Question by:goingolfn99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20362429

Are you using a subform?

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20362445
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20362463
also check if the control you want to set the focus is enabled.
if not you have to enable the control first
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 50 total points
ID: 20362554
" 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
 

Author Comment

by:goingolfn99
ID: 20367519
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
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 450 total points
ID: 20367585
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
 

Author Comment

by:goingolfn99
ID: 20367698
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
 

Author Comment

by:goingolfn99
ID: 20367707
yes, the listbox that i want setfocus is enabled.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20367731
is employeeId a number type of data?



is Me.txtID the same as the employeeID?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20367755
better that you upload the zip db here www.ee-stuff.com
0
 

Author Comment

by:goingolfn99
ID: 20367801
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
 

Author Closing Comment

by:goingolfn99
ID: 31411325
THANKS GUYS FOR THE EFFORT AND QUICK RESPONSE
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question