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
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