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

Setting value of control w. VBA code

Status
Not open for further replies.

Chrisbi

Technical User
Nov 27, 2002
26
US
I'm not sure this is possible but... I have a subreport which contains 1 field--this is a statement containing various fields in subreport row source. I tried setting value (me.field ="..."] in vbo in on open event but that doesnt seem to work. Reason I want to do this is that I will use report for several forms & depending on sending form, the language (& fields) of statement will vary. I would appreciate any suggestions. Thank you.
 
Hi!

If I understand you correctly, you wan't to change a textbox controlsource "on the fly" based on which form you're calling it from.

If so, do the appropriate testing and change the controlsource by:

me!txtYourTextControl.ControlSource="FieldName"

Note - make sure your text controls name isn't the same as a possible field. Add a "txt" prefix to the name.

HTH Roy-Vidar
 
Thanks--The only thing I'm not sure of is where would I put the code for the controlsource. I tried in the report 'on open' event but it doesn't seem to work...
 
You can only set a ControlSource for reports in the Report_Open. The code will generate an error if encountered anywhere else.

You can't enter it exactly the same way it's done on the design layout. Your field names must be enclosed in square brackets or they will be interpreted as text.
me!txtYourTextControl.ControlSource="FieldName" should be
Me.txtYourTextControl.ControlSource = "[FieldName]"

If you need to use a calculated field you need to use "=" & " before the value:
Me.txtYourTextControl.ControlSource = "= " &"[FieldName] + 1"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top