Solved

Error 2110

Posted on 2007-11-27
12
387 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bind Combobox 4 29
How can I create a table in a linked database, in VB? 7 17
How autopopulate number field with 2 different criteria 9 49
Excess tables to Excel BackUp 3 28
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 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

21 Experts available now in Live!

Get 1:1 Help Now