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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign variable value to Unbound text box control 1

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
Is it possible to assign a string variable value to an unbound text box control using a visual basic statement:

txtCounty = strCounty

This results in a runtime error 2448, You cannot assign a value to this object.

I have tried several methods including txtCounty.ControlSource, txtCounty.Default value which results in a compile error.

I've also tried to set the control source property to =[me].[strcounty] and get the #Name error.

I've done this with dates with no problem but can't figure out how (or if I can) assign a string value.

Thanks. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Use an event such as a command box (or any of many such) and in the event code , use the following code.

me.txtcountry = strcountry


Rollie
 
it should work.

TxtMyControl.Value = StrMyString

unless your control is set to a specific format. Or try to set focus to it like

TxtMyControl.SetFocus
TxtMyControl.Value = StrMyString

If it doesn't work, then how and at what point are you trying to populate the field with data? "The greatest risk, is not taking one."
 
Larry,

You can assign a string variable to a text box, and in fact I do it frequently. I recall getting this error a few weeks ago, but for the life of me I can't remember what caused it or what I did to correct it. Please post more of your code and maybe it will jog my memory.

Best,
dz
 
ctorock:

You do, indeed, rock.

Color me dense; I don't know why I couldn't figure this out myself.

Thanks much for the response. The value property was what it wanted. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
You shouldn't have to use the Value property, but if it works, it works. I generally use the Value property to remove any ambiguity, but it isn't necessary.

txtCounty is equal to txtCounty.Value

I suspect that something else was causing this problem, and that the Value property overrode it.

dz
 
dz:

I had tried that and received the error message: 2448, You cannot assign a value to this object.

As I said, I have done the direct assignment with dates and have never exerienced a problem. For some reason, it did not like the string value.

I should have mentioned that I am working with Access 97; don't know if that makes a difference. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Unless I am mistaken the usual cause of this error is attempting to assign a vlaue to a textbox that has a statement, any statement in its ControlSource property. The ControlSource must be empty.

Say you create a textbox called Text0 and set its ControlSource to ="Hello".

Now add this to the field's Click event: Text0 = Date

Run the form and see the box has Hello in it. Now click the box to trigger the event code. You get the error code 2448.

Now put the form in design mode and click in the box to edit the control source by deleting ="hello". Note do not remove the statement using the Property Sheet.

Now run the form and click the textbox. You get the error again even though the ControlSource statement is gone.

OK back to design mode and now double click the box to activate the property sheet. Put the cursor in the CcontrolSource field and press the delete key at least ten times to delete the non existent text. I know, you think I'm mad, but humor me and do it anyway.

Now run the form again and click the text box. There should be no error this time, just the date appearing in the field. Weird or what?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top