Populate an Unbound TextBox from a Query

ddrew

seasoned user
Local time
Today, 07:34
Joined
Jan 26, 2003
Messages
911
How can I populate an unbound TextBox from a query. The forms data is all based on a different query. But this one is a count, so is a seperate query.
Code:
 Me.txtCount = [qryCountAllMembers]![CountOfMembersID]
This is what I thought but it dosent populate anthing!
 
You cannot populate a Control directly from a Query, in this manner. You'll have to use the DCount() function against the table or query that holds the data.

Putting DCount into Help should give you what you need in the way of instructions.

Linq ;0)>
 
Im now getting a count of "1" on my form, but the querry is saying "4"

Code:
        Me.txtCount = DCount("[CountOfMembersID]", "qryCountAllMembers")
 
It looks like you're running the DCount against the query you were using to do the math. You need to run it against the MemberID field, not against the CountOfMembersID field, which I assume is a Calculated field in the query.
 
Last edited:
It looks like you're running the DCount against the query you were using to do the math. You need to run it against the MemberID field, not against the CountOfMembersID field, which I assume is a Calculated field in the query.

Can I assign a value from a query to a text box without writing VBA code ? please please help.

Thanks.
Moses
 
Im not to clever at this but put this as the Source
Code:
= DCount("[ID]", "QueryName")

Substitue ID for the ID field name in your query and QueryName for the name of your query
 
Can I assign a value from a query to a text box without writing VBA code
No! It's not complicated, but you will have to use VBA.

What kind of Query are you talking about, and what kind of field. If the field is an Aggregate, such as in ddrew's scenario where he wanted the total number of records in a domain, his advice about using DCount is probably the answer.

To assign a single value from a query you'd use the related function DLookup, rather than DCount. The syntax is similar and you'd probably need to include the third argument which provides a Criteria to pinpoint the specific record you're looking for.

A bit more explanation, on your part, would probably help us to help you here.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom