how populate a textbox with a VBA created query

dogdays

Active Member
Joined
Apr 28, 2008
Messages
434
Office Version
  1. 2007
W7 32bit pro, Access 2003
I have created a query to populate a textbox, the query looks OK but what do I have to do to actually get the results of the query in the textbox?

Code:
            ' populate the summary boxes
            ' first create the queries
            strQueryName = "qryAcquisitionsFund1SumBookOrders"
            If utfnQueryExists(strQueryName) Then
                dbs.QueryDefs.Delete strQueryName
            End If

            strQuery = "SELECT SUM(nNumberOrdered) FROM " & gcstrAcquisitionsTableName
            strQuery = strQuery & " WHERE tStatus <> '" & gcstrStatusNew & "'"
            strQuery = strQuery & " AND nFund = 1 "
            strQuery = strQuery & " AND (dtOrdered >= #" & strStartDate & "# AND dtordered <= #" & strEndDate & "#) "
            Set qryDef = dbs.CreateQueryDef(strQueryName, strQuery)
            Me.txtFund1Ordered.ControlSource = strQueryName
With the above code I end up with #Name in the textbox.

tia Jack
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I didn't think textboxes work this way (with queries as record sources - that's a combobox type of thing - someone correct me if I'm wrong!).
But I think what you are doing would work if you constructed a DSUM() function instead of a query. That should be possible.

ξ
 
Upvote 0
Xenou:
Took your advice and did DSum and DCount. All works well. Thank you.

Jack
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top