Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a calculated text box

Status
Not open for further replies.

dusteater

Programmer
Aug 15, 2001
13
US
I have a form that has a combobox that I use for a search field. Also on that form there are several text boxes that reflect the different fields of the database. The textboxes are bound to the database so that changes can be made easily.When a person selects a data member in the combobox the textboxes reflect the data for the selected item. The problem is that I have one text bix that I want to show certain text depending on the data in one of the textboxes. I am using the AfterUpdate method of the combobox and all works fine until I try to place the data in the text box. Here is the code:
Private Sub cmbCDC_AfterUpdate()

' Find the record that matches the control.
If IsNull(cmbCDC) Then Exit Sub
Me.RecordsetClone.FindFirst "[ID] = " & Me![cmbCDC]
Me.Bookmark = Me.RecordsetClone.Bookmark
txtClass.SetFocus
If txtClass.Text = "" Then
txtLevel.SetFocus
txtLevel.Text = "Unknown"
Exit Sub
End If
txtClass.SetFocus
Select Case CInt(txtClass.Text)

Case 0 To 26
txtLevel.SetFocus
txtLevel.Text = "Level 1"
txtName.SetFocus
Case 27 To 34
txtLevel.SetFocus
txtLevel.Text = "Level II"
txtName.SetFocus
Case 35 To 50
txtLevel.SetFocus
txtLevel.Text = "Level III"
txtName.SetFocus
Case Is > 50
txtLevel.SetFocus
txtLevel.Text = "Level IV"
txtName.SetFocus
End Select

End Sub

The problem comes when I try to place the text into the textbox. I get the following error: Run-Time Error'2115'
The macro or function set to the BeforeUpdate orValidationRule property for this field is preventing Microsoft Access from saving ther data in the field.

I do not have either of these set, so what could be the problem?
Thanks in advance
Rick
 
Make sure that txtLevel does not have a BeforeUpdate event that is doing editing. Also, make sure that txtLevel does not have an input mask or format that is inconsistent with the value that you are putting in the field.

This error is happening after you've populated the Text property of the textbox and before you SetFocus to the next field.

By the way, you could try just populating the textbox without referring to the Text property:

Me.txtLevel = "Level III"

See if this gives you the same error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top