Solved

Error 2110

Posted on 2007-11-27
12
388 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
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

786 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