Can not Set Focus to a Text Box - Error 2110

G

Guest

I am trying to create an Access 2003 Front End to a SQL Server 2005 database.
The database is simple, only a few tables.

I am creating a form which is bound to a table that contans records of calls
by a customer. There is another table of Customers, that has customer
meta-data - Address, Phone Number, etc. There is a combo box on the form
containing all of the customers in the custmers table. My client wants the
customer data copied to the same fields in his call record table, so the
information can be edited for this call. I know this is a bad design, but
the client insists.

I have code in the click event of the combo box that copies the information
for the chosen customer to the text boxes on the form for the call record.
The code is below. I get an error when I try to set the focus to the SECOND
text box in the flow of the code. No matter which text box I start with, I
always get the error on the second one. All text boxes are Visible, Enabled,
and not Locked.

I would appreciate any help you can give. I do not do much Office
programming, so maybe there is a better way to accomplish my task. The
client insists on an Access front end with minimal VB code.

Private Sub cmbCustomer_Click()

' This routine loads the address and phone data for the company when the
' company is chosen from the drop down list.

On Error GoTo ErrorHandler

' Get the company number
Dim companyNumber As String

companyNumber = cmbCustomer.Column(0)

' Get the data for this company
Dim myData As DAO.Recordset
Dim sql As String

sql = "SELECT * FROM dbo_Customers WHERE [Company Number] = '" &
companyNumber & "'"

Set myData = Access.CurrentDb.OpenRecordset(sql, dbOpenSnapshot, dbReadOnly)

' Set the value of the form fields for this customer
If Not myData.EOF Then
' This line works, no matter which text box I try first
Forms![Service Calls]![Customer Number].SetFocus
Forms![Service Calls]![Customer Number].Text = myData.Fields("[Company
Number]").Value

' Error 2110 on this line, no matter which text box is second
Forms![Service Calls]![Company Address 1].SetFocus
Forms![Service Calls]![Company Address 1].Text = myData.Fields("[Company
Address 1]").Value

Forms![Service Calls]![Company Address 2].SetFocus
Forms![Service Calls]![Company Address 2].Text = myData.Fields("[Company
Address 2]").Value

Forms![Service Calls]![Company City].SetFocus
Forms![Service Calls]![Company City].Text = myData.Fields("[Company
City]").Value

Forms![Service Calls]![Company State].SetFocus
Forms![Service Calls]![Company State].Text = myData.Fields("[Company
State]").Value

Forms![Service Calls]![Company Country].SetFocus
Forms![Service Calls]![Company Country].Text = myData.Fields("[Company
Country]").Value

Forms![Service Calls]![Company Zip].SetFocus
Forms![Service Calls]![Company Zip].Text = myData.Fields("[Company
Zip]").Value

Forms![Service Calls]![Company Phone].SetFocus
Forms![Service Calls]![Company Phone].Text = myData.Fields("[Company
Phone]").Value

Forms![Service Calls]![Company Fax].SetFocus
Forms![Service Calls]![Company Fax].Text = myData.Fields("[Company
Fax]").Value
End If

myData.Close
Set myData = Nothing

Exit Sub

ErrorHandler:

Select Case Err.Number
Case 94
Resume Next
Case 2115
' This error is generated when the Text property is set, Even though
the
' Text property is set correctly
Resume Next
Case Else
MsgBox "Error " + Err.Description, vbInformation, "Error Message
Window"
End Select
End Sub
 
G

Guest

I'm sorry to replay to my own posting, but I found a solution and I wanted it
to be here in case someone else was having a similar problem.

I was setting the text box properties using code like this:

Forms![Service Calls]![Customer Number].Text = myData.Fields("[Company
Number]").Value

This was generating an Error, number 2115, which I was ignoring. I changed
the code to this:

Forms![Service Calls]![Customer Number] = myData.Fields("[Company
Number]").Value

I removed the Text property. This eliminated the error 2115, and I was able
to set the focus to all text boxes and set their values. I'm not sure why
this made a difference, so if anyone woudl like to educate me I would like to
know.
--
Thanks,

Bill Manring
Wavefront Software, Inc.


Bill Manring said:
I am trying to create an Access 2003 Front End to a SQL Server 2005 database.
The database is simple, only a few tables.

I am creating a form which is bound to a table that contans records of calls
by a customer. There is another table of Customers, that has customer
meta-data - Address, Phone Number, etc. There is a combo box on the form
containing all of the customers in the custmers table. My client wants the
customer data copied to the same fields in his call record table, so the
information can be edited for this call. I know this is a bad design, but
the client insists.

I have code in the click event of the combo box that copies the information
for the chosen customer to the text boxes on the form for the call record.
The code is below. I get an error when I try to set the focus to the SECOND
text box in the flow of the code. No matter which text box I start with, I
always get the error on the second one. All text boxes are Visible, Enabled,
and not Locked.

I would appreciate any help you can give. I do not do much Office
programming, so maybe there is a better way to accomplish my task. The
client insists on an Access front end with minimal VB code.

Private Sub cmbCustomer_Click()

' This routine loads the address and phone data for the company when the
' company is chosen from the drop down list.

On Error GoTo ErrorHandler

' Get the company number
Dim companyNumber As String

companyNumber = cmbCustomer.Column(0)

' Get the data for this company
Dim myData As DAO.Recordset
Dim sql As String

sql = "SELECT * FROM dbo_Customers WHERE [Company Number] = '" &
companyNumber & "'"

Set myData = Access.CurrentDb.OpenRecordset(sql, dbOpenSnapshot, dbReadOnly)

' Set the value of the form fields for this customer
If Not myData.EOF Then
' This line works, no matter which text box I try first
Forms![Service Calls]![Customer Number].SetFocus
Forms![Service Calls]![Customer Number].Text = myData.Fields("[Company
Number]").Value

' Error 2110 on this line, no matter which text box is second
Forms![Service Calls]![Company Address 1].SetFocus
Forms![Service Calls]![Company Address 1].Text = myData.Fields("[Company
Address 1]").Value

Forms![Service Calls]![Company Address 2].SetFocus
Forms![Service Calls]![Company Address 2].Text = myData.Fields("[Company
Address 2]").Value

Forms![Service Calls]![Company City].SetFocus
Forms![Service Calls]![Company City].Text = myData.Fields("[Company
City]").Value

Forms![Service Calls]![Company State].SetFocus
Forms![Service Calls]![Company State].Text = myData.Fields("[Company
State]").Value

Forms![Service Calls]![Company Country].SetFocus
Forms![Service Calls]![Company Country].Text = myData.Fields("[Company
Country]").Value

Forms![Service Calls]![Company Zip].SetFocus
Forms![Service Calls]![Company Zip].Text = myData.Fields("[Company
Zip]").Value

Forms![Service Calls]![Company Phone].SetFocus
Forms![Service Calls]![Company Phone].Text = myData.Fields("[Company
Phone]").Value

Forms![Service Calls]![Company Fax].SetFocus
Forms![Service Calls]![Company Fax].Text = myData.Fields("[Company
Fax]").Value
End If

myData.Close
Set myData = Nothing

Exit Sub

ErrorHandler:

Select Case Err.Number
Case 94
Resume Next
Case 2115
' This error is generated when the Text property is set, Even though
the
' Text property is set correctly
Resume Next
Case Else
MsgBox "Error " + Err.Description, vbInformation, "Error Message
Window"
End Select
End Sub

--
Thanks,

Bill Manring
Wavefront Software, Inc.
 
G

Guest

The error wasn't coming from setting the value of the text box. It was
coming on the line before. Error 2110 is "can't move the focus to the
control".

I never did figure out why you were setting the focus to each field before
updating is. I will bet that you took out the setfocus lines when you were
making changes. That is what made the problem go away.

Bill Manring said:
I'm sorry to replay to my own posting, but I found a solution and I wanted it
to be here in case someone else was having a similar problem.

I was setting the text box properties using code like this:

Forms![Service Calls]![Customer Number].Text = myData.Fields("[Company
Number]").Value

This was generating an Error, number 2115, which I was ignoring. I changed
the code to this:

Forms![Service Calls]![Customer Number] = myData.Fields("[Company
Number]").Value

I removed the Text property. This eliminated the error 2115, and I was able
to set the focus to all text boxes and set their values. I'm not sure why
this made a difference, so if anyone woudl like to educate me I would like to
know.
--
Thanks,

Bill Manring
Wavefront Software, Inc.


Bill Manring said:
I am trying to create an Access 2003 Front End to a SQL Server 2005 database.
The database is simple, only a few tables.

I am creating a form which is bound to a table that contans records of calls
by a customer. There is another table of Customers, that has customer
meta-data - Address, Phone Number, etc. There is a combo box on the form
containing all of the customers in the custmers table. My client wants the
customer data copied to the same fields in his call record table, so the
information can be edited for this call. I know this is a bad design, but
the client insists.

I have code in the click event of the combo box that copies the information
for the chosen customer to the text boxes on the form for the call record.
The code is below. I get an error when I try to set the focus to the SECOND
text box in the flow of the code. No matter which text box I start with, I
always get the error on the second one. All text boxes are Visible, Enabled,
and not Locked.

I would appreciate any help you can give. I do not do much Office
programming, so maybe there is a better way to accomplish my task. The
client insists on an Access front end with minimal VB code.

Private Sub cmbCustomer_Click()

' This routine loads the address and phone data for the company when the
' company is chosen from the drop down list.

On Error GoTo ErrorHandler

' Get the company number
Dim companyNumber As String

companyNumber = cmbCustomer.Column(0)

' Get the data for this company
Dim myData As DAO.Recordset
Dim sql As String

sql = "SELECT * FROM dbo_Customers WHERE [Company Number] = '" &
companyNumber & "'"

Set myData = Access.CurrentDb.OpenRecordset(sql, dbOpenSnapshot, dbReadOnly)

' Set the value of the form fields for this customer
If Not myData.EOF Then
' This line works, no matter which text box I try first
Forms![Service Calls]![Customer Number].SetFocus
Forms![Service Calls]![Customer Number].Text = myData.Fields("[Company
Number]").Value

' Error 2110 on this line, no matter which text box is second
Forms![Service Calls]![Company Address 1].SetFocus
Forms![Service Calls]![Company Address 1].Text = myData.Fields("[Company
Address 1]").Value

Forms![Service Calls]![Company Address 2].SetFocus
Forms![Service Calls]![Company Address 2].Text = myData.Fields("[Company
Address 2]").Value

Forms![Service Calls]![Company City].SetFocus
Forms![Service Calls]![Company City].Text = myData.Fields("[Company
City]").Value

Forms![Service Calls]![Company State].SetFocus
Forms![Service Calls]![Company State].Text = myData.Fields("[Company
State]").Value

Forms![Service Calls]![Company Country].SetFocus
Forms![Service Calls]![Company Country].Text = myData.Fields("[Company
Country]").Value

Forms![Service Calls]![Company Zip].SetFocus
Forms![Service Calls]![Company Zip].Text = myData.Fields("[Company
Zip]").Value

Forms![Service Calls]![Company Phone].SetFocus
Forms![Service Calls]![Company Phone].Text = myData.Fields("[Company
Phone]").Value

Forms![Service Calls]![Company Fax].SetFocus
Forms![Service Calls]![Company Fax].Text = myData.Fields("[Company
Fax]").Value
End If

myData.Close
Set myData = Nothing

Exit Sub

ErrorHandler:

Select Case Err.Number
Case 94
Resume Next
Case 2115
' This error is generated when the Text property is set, Even though
the
' Text property is set correctly
Resume Next
Case Else
MsgBox "Error " + Err.Description, vbInformation, "Error Message
Window"
End Select
End Sub

--
Thanks,

Bill Manring
Wavefront Software, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top