DSum With Variable expression based on TextBox Value

OasisUnknown

New Member
Joined
Oct 15, 2015
Messages
46
Hello All,

Is it possible to use a DSUM to count a column of data off of a cross tab query using a textbox as a variable source.

I know the answer to the first part is yes (being able to use a DSUM to count a column of data off the query.)

=DSum("[25B1O]","qryAuthPosCount_CrossTab")

when I run this on a text box on my dashboard form I get the result 5. Which is what I expected to return.


After my base line check to see if it was possible I started to expand.

I linked up a combobox to display its value selected in a text box on the form so when I change selections the text box updates
(Ie. When I select 25B1O the textbox displays 25B1O, When I select 26A1O The textbox displays 26A1O)

I am trying to use that textbox to give a variable result to the textbox that holds the DSUM

Here are some examples of things that I have tried.

=DSum([Forms]![sfrmMOSISnapshot]![SL1MOSTxt],"[qryAuthMOSCount_CrossTab]")
=DSum([Forms]![sfrmMOSISnapshot]![SL1MOSTxt].[Text],"[qryAuthMOSCount_CrossTab]")

=DSum("[Forms]![sfrmMOSISnapshot]![SL1MOSTxt]","[qryAuthMOSCount_CrossTab]")
=DSum("[Forms]![sfrmMOSISnapshot]![SL1MOSTxt].[Text]","[qryAuthMOSCount_CrossTab]")

I have tried many other variations but nothing is working. I have even tried to cast the textbox to a string and then use that.

=DSum("CStr([Forms]![sfrmMOSISnapshot]![SL1MOSTxt].[Text])","[qryAuthPOSCount_CrossTab]")

Nothing is working except for when I hard Code the value into the DSUM
=DSum("[25B1O]","qryAuthPosCount_CrossTab")


Anyone have any suggestions on how I can base my DSum off the text that is stored in a textbox?
 
Otherwise, possible the question is why use crosstab at all? you want a single result. So just use a sum formula on the data (that's all crosstabs do - sum by two criteria, row and column).

Xenou, This statement got me to write my calculation in a different way and I was able to solve my current issue.

instead of
Code:
DSum([myTextBox].[Value],"[myQuery_CrossTab]")

I used
Code:
=Nz(DSum("[AUTHSTR]","[myTable]","[myPosition]=[SL1MOSTxt]"),0)

So basically my criteria went to the authorized source (the number I wanted to count).
I then took that directly from my table
and just did a criteria search on my variable.
wrapped that in an Nz and now everything works as I expected it too.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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