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

#Name? date field on a form 2

Status
Not open for further replies.

villica

Programmer
Feb 25, 2000
332
CA
I am trying to set the control source of a date field on a form as follow

Set rst = db.OpenRecordset("shipplan", dbOpenDynaset)
Me!LOGDATE.ControlSource = rst("logdate")

When I step thru the code, I can see that the value is correct, but it does not display on the form properly.
Instead I get #Name?.

Any suggestions.
thanks

villica
 
Have you tried this ?
Me!LOGDATE.Value = rst("logdate")


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
First off you don't have FIELDS on Forms

Fields are in TABLES

Forms have CONTROLS.

So from your code I'm assuming that the control NAME is LOGDATE

What you need is
Set rst = db.OpenRecordset("shipplan", dbOpenDynaset)
LOGDATE.ControlSource = rst!logdate


That is just simplyfying what you had before ( getting rid of the unnecessary stuff ), but it won't fix your problem because you problem lies in the fact that the text string what is supplied by rst!LogDate does not appear as a field name in the FORM's RecordSource.

You need to look at the Record Source that the form is bound to and see how the field that you want to bind this control to is spelt. the correct the data in the table shipplan.




'ope-that-'elps


G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
PHV is correct that you (from your brief description) want to set the "value" property of the control which we assume is bound to a field in your form's record source.

My question... does shipplan only return a single record or are happy with the logdate value from any record?

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
What have I missed dhookom ?

I've re-read the original post and there is nothing in there, that I can see, to suggest that villica needs to go anywhere near the .Value property.

He is trying to set the .ControlSource

And anyway with
Me!LOGDATE.Value = rst("logdate")
the Me! is, in this context, a tautology and can be omitted
.Value is not appropriate either.

So IFF he was trying to set the contents of the control then
LOGDATE = rst!logdate
is all that is needed.





G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Hi

Like LittleSmudge I am confused as to what you are trying to do.

I suspect you are trying to set the value of logdate from the recordset into an unbound control on the form in which case

Set rst = db.OpenRecordset("shipplan", dbOpenDynaset)
LOGDATE = rst("logdate")

but maybe you are trying to set the controlsource in code in which case:

Set rst = db.OpenRecordset("shipplan", dbOpenDynaset)
Me!LOGDATE.ControlSource = "logdate"

this presuposes that the form is bound to a recordset containing LogDate



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks PHV AND Ken, they both worked, but I am using Ken solutions Me!LOGDATE.ControlSource = "logdate"



villica
 
Do you realize that the following line of code doesn't use the recordset?
Code:
    Me!LOGDATE.ControlSource = "logdate"
All it does is bind the control to the field named [logDate] in the form's record source. Any code that defines a recordset or whatever is wasted.

Do you have a good reason why you would want to assign a control source property at run-time rather than in design of the form?


Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Hi

Yes Duane, I would agree, I thought I had explained that in my post with my two code examples, but it would appear not.

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Duane, you said in an earlier post
Do you have a good reason why you would want to assign a control source property at run-time rather than in design of the form?

Yes, I have done something similar in a few applications in order to be able to re-use complex forms for slightly different purposes.
It saves having to create almost duplicate forms and it Guarantees that the user sees the same interface in each version.
( you don't run any risk of the various versions getting out of sink with updates etc. )

To me it is not that 'out of the ordinary'.

It is after all only the Forms based equivalent to 'Pointer to a Pointer' in Pascal etc.
( Or am I showing my age there ? )




G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
I understand that LittleSmudge and Ken understand the code and what is happening but my concern is that villica doesn't have a full understanding. Since the recordset wasn't used to find a value to set the control source then I doubt the original objective (which I assumed was to dynamically set a control source property or was it to set a value of a control dynamically) is being met.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top