Unable too update text box (1 Viewer)

steadyonabix

New member
Local time
Today, 05:18
Joined
Mar 11, 2009
Messages
5
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

Super Moderator
Local time
Today, 05:18
Joined
Jul 10, 2007
Messages
5,906
The code you posted will always go through the error handler even if it workks correctly!
Try this
Code:
Private Sub lstFileList_Click()
On Error GoTo zz
txtReviewComments.SetFocus
txtReviewComments.Text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[COLOR=red]exit sub
[/COLOR]zz:
MsgBox "Error in function SizeRequestingTeamArray - " & Err.DESCRIPTION
End Sub
 

steadyonabix

New member
Local time
Today, 05:18
Joined
Mar 11, 2009
Messages
5
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

Allan
Local time
Today, 05:18
Joined
Nov 29, 2004
Messages
336
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

New member
Local time
Today, 05:18
Joined
Mar 11, 2009
Messages
5
Allan

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

Why does it work though?

Cheers

Brad
 

allan57

Allan
Local time
Today, 05:18
Joined
Nov 29, 2004
Messages
336
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

Smeghead
Local time
Yesterday, 21:18
Joined
Jan 12, 2001
Messages
32,059
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

New member
Local time
Today, 05:18
Joined
Mar 11, 2009
Messages
5
Cheers, looks like I should go back through the code and change all of my setfocus statements to this syntax....
 

Users who are viewing this thread

Top Bottom