UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Setting Control Source With Dlookup, Access 2016    
 
   
AussieFred
post Jul 4 2019, 09:06 PM
Post#1



Posts: 27
Joined: 2-December 16



I wish to bind a text box to a field in my table.

In Form Load I have

Me.Text0.ControlSource= DLookup("Test", "Table1", "Cat = '" & Me.OpenArgs & "'")

I get #Name?

I've tested Dlookup in a Msgbox and it is ok.
This post has been edited by AussieFred: Jul 4 2019, 09:06 PM
Go to the top of the page
 
GroverParkGeorge
post Jul 4 2019, 09:45 PM
Post#2


UA Admin
Posts: 35,516
Joined: 20-June 02
From: Newcastle, WA


If the CONTROL has the same name as the FIELD to which it is bound, then it is likely it will raise this error.

So, try changing the name of the CONTROL to something else if that is the case.

It looks like your control is actually named Text0, which is the default name used by Access and probably not the best choice anyway. The same is true for "Table1". Do you really have a table by that name? Not a particularly good choice for an object name, I think.

So, the next thing to validate is that you are actually passing a valid value via OpenArgs.

I'm not sure I've ever seen an arrangement like this, where a control is bound to different fields in a table at different times. Can you elaborate on why that would be useful?

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
projecttoday
post Jul 4 2019, 10:45 PM
Post#3


UtterAccess VIP
Posts: 10,866
Joined: 10-February 04
From: South Charleston, WV


You're wanting to set the control source. I think this would require a character string. The way you have it is setting the actual value.

I agree that Text0 is not a good name.

--------------------
Robert Crouser
Go to the top of the page
 
tina t
post Jul 5 2019, 12:11 AM
Post#4



Posts: 6,023
Joined: 11-November 10
From: SoCal, USA


QUOTE
Me.Text0.ControlSource= DLookup("Test", "Table1", "Cat = '" & Me.OpenArgs & "'")

I get #Name?

i just did a quick test on a bound form, where i used a table as the form's RecordSource, and added controls bound to the fields in the table. all good, as expected. then i changed the ControlSource of one of the controls to X, which is not the name of any field in the table used as the form's RecordSource. and now in Form view the control shows

#Name?

so there's the question: in the form's RecordSource, have you included every field that may be assigned to the ControlSource of Text0?

and, just btw, i agree with George and Robert that the names are not good - though i'm hoping you just made a quickie table and form to test your idea - and the requirement itself seems strange. in fact, it makes me wonder if the table design is not normalized, storing data in fieldnames, such as CategoryA, CategoryB, etc. are you working with an inherited db with a design you're stuck with? i can identify with that pain, for sure! ;) but if it's your design, and if it is not-normalized, this might be a good time to review your tables/relationships setup.

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
GroverParkGeorge
post Jul 5 2019, 03:04 AM
Post#5


UA Admin
Posts: 35,516
Joined: 20-June 02
From: Newcastle, WA


It just dawned on me. Are you actually trying to set the ControlSource for the control? Or are you actually trying set different Values for the control. Or even perhaps default values?

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
projecttoday
post Jul 5 2019, 08:38 AM
Post#6


UtterAccess VIP
Posts: 10,866
Joined: 10-February 04
From: South Charleston, WV


This example

Me.Text0.ControlSource = "field1"

sets the control source to a field called "field1"

--------------------
Robert Crouser
Go to the top of the page
 
GroverParkGeorge
post Jul 5 2019, 08:41 AM
Post#7


UA Admin
Posts: 35,516
Joined: 20-June 02
From: Newcastle, WA


Yes, that's the way it's presented and it is a puzzle to me. And that's why I wonder if perhaps the intent was not to change the Control Source (which means there has to be a Repeating Column in that table in order for fields to be interchangeable), but to assign a value.

In any case, we need the OPs feedback to move ahead.


--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th August 2019 - 03:55 PM