Display Query field on form - correct format needed.

fpperry

Earnest Dabbler
Local time
Yesterday, 23:34
Joined
Jan 13, 2003
Messages
9
I have an unbound text box that I want to use to display the one field result of a query. I've tried this code but wont work:
DoCmd.OpenQuery "qryGetMax"
Me.txtMax.Value = [qryGetMax]![MaxOfWgt]

The query give the correct result but I can't assign it to the text box. What am I doing wrong? Please!!!
 
With your form in design view and the unbound text box selected, bring up the properties box. On the "data" tab, control source should be "=[qryGetMax]![MaxOfWgt]". You shouldn't need the code.

See if that works,

Matt
 
I tried that the 1st thing. I get a "#Name?" displayed as a result. And I can't findout what that means anywhere thru the Help system.
 
Last edited:
Well, I was way off base with that answer! It should be so simple.

Anyway, this may work better (use with "current" event or whichever is most appropriate):

Dim varX As Variant
varX = DLookup("[MaxOfWgt]", "[qryGetMax]")
Me.txtMax = varX

Let me know if this is wide of the mark...

Matthew
 
I know it should work, but i get a 'Can;t assign a value to this object' error message.
 
Why not just set the control source of the unbound textbox to =DLookup etc
 

Users who are viewing this thread

Back
Top Bottom