View Full Version : Unable too update text box


steadyonabix
03-11-2009, 02:47 AM
Hi

I am having a strange problem I have not come across before.

I am putting a database together and for the first time I am not using bound controls but writing specific functions to query the backend SQL server database and update the MS Access front end controls.

These functions work well and the controls are populated with the data when the form loads. Now I am writing functions to change the data displayed in some controls when the user clicks on a list of file names in a listbox. However when I try to update a text box with new text for a second time I get the error: -

"The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field."

The validation rule is blank and the BeforeUpdate function does not exist so I cannot understand why it is giving me this error or why it is trying to save anything as no record source is defined for the control, (or any control).

Just creating the simple sub: -

Private Sub lstFileList_Click()
On Error GoTo zz
txtReviewComments.SetFocus
txtReviewComments.Text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
zz:
MsgBox "Error in function SizeRequestingTeamArray - " & Err.DESCRIPTION
End Sub

gives this error.

Anyone have any ideas as to what the problem is?

Thanks

Bradley

Rabbie
03-11-2009, 02:54 AM
The code you posted will always go through the error handler even if it workks correctly!
Try this

Private Sub lstFileList_Click()
On Error GoTo zz
txtReviewComments.SetFocus
txtReviewComments.Text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
exit sub
zz:
MsgBox "Error in function SizeRequestingTeamArray - " & Err.DESCRIPTION
End Sub

steadyonabix
03-11-2009, 03:32 AM
Cheers

Sorry I should have explained I put a break point on the error message to scrape it for this post.

This is not the eventual code I want to write I just put it together to demonstrate that I get the error when trying to do a simple update to the text property.

Thanks

allan57
03-11-2009, 04:14 AM
Hi try the following, as the text box is unbound:

Private Sub lstFileList_Click()
On Error GoTo zz
txtReviewComments = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

exit sub

zz:
MsgBox "Error in function SizeRequestingTeamArray - " & Err.DESCRIPTION
End Sub

steadyonabix
03-11-2009, 05:46 AM
Allan

Your name is now Bhagwan my guru :D, thanks very much.

Why does it work though?

Cheers

Brad

allan57
03-12-2009, 08:47 AM
When you write to a text box using the .Text extension, you are actually updating the control source of the text box directly, therefore only use this method with a bound control.

boblarson
03-12-2009, 09:14 AM
When you write to a text box using the .Text extension, you are actually updating the control source of the text box directly, therefore only use this method with a bound control.

And, also when you use .Text you need to have focus on the control (which I know you had done) but if you don't use it and use the default (which is .Value - even if you leave it off) then you don't have to have focus on the control.

steadyonabix
03-16-2009, 05:03 AM
Thanks thats helpful

steadyonabix
03-16-2009, 05:04 AM
Cheers, looks like I should go back through the code and change all of my setfocus statements to this syntax....