Solved

Error 2110

Posted on 2007-11-27
12
386 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 119

Expert Comment

by:Rey Obrero
ID: 20362429

Are you using a subform?

0
 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
 
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 119

Accepted Solution

by:
Rey Obrero 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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 119

Expert Comment

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



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

Expert Comment

by:Rey Obrero
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now