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

Control Sources in Access 1

Status
Not open for further replies.

ADW

Programmer
Jun 21, 2001
50
GB
Is there a way of specifiying a data control source from within a text field? Is there any code?
 
Can you describe in a bit more detail what you're trying to do? Which application are you working with?
 
My apologies, I'm using Access what I want to do is to select a control source from within a text box. As there is no feature to do that I was wondering if there was any code to allow me to do this.
 
Ooops.

I guess the answer to the 2nd question would be 'Access'

Sorry, having a bad-brain day . . .
 
OK, understood.

I did something like this a while ago, where the user selected the actual back end db from a choice, so in theory the answer should be yes.

I'll have a dig around my dusty archives and get back to you.


 
This might be what you're looking for. I've kind of knocked this up in a hurry, so suggest you experiment on a copy!

I assume:

- You've got the list appearing in the textbox ok.
- The textbox is on the same form as the field that you want to change the control source for.

I'll refer to 'textbox1' and 'field1', with 2 possible controlsources in the table, called 'ctrl1' and ctrl2'.

Make sure the textbox is unbound - it might start creating rogue records if it's a field in the table!

Place this code on for example the 'afterupdate' event for the textbox:

dim cts as string
cts = me.textbox1.value
field1.controlsource = cts

This code will modify the control source for field1 to the exact text in textbox1, so make sure your list of choices are valid. if it is not, you should see something like '#name?' appear in the controled field.

Hope this points in the right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top