Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2010, 09:13 AM
Authorized User
Points: 71, Level: 1
Points: 71, Level: 1 Points: 71, Level: 1 Points: 71, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Question Specifying the value of a combo box in a DSum expression

I am trying to create a simple household inventory application. I have an unbound text box on my form that displays the total value of each household category such as appliances, furniture, and so on. I also have a select category combo box that, when updated, sets the form to display only records in the selected category. The code below calculates the total value of a specific category:

txtTotalForSelectedItems = DSum("([Cost] + ([Cost] * [TaxRate]) + [DeliveryCost])", "tblItemInfo", "[Category] = 'Appliances'")

In the code above how do I replace the explicit category name 'Appliances' with whatever the value of the combo box is when it is updated?
I tried:

txtTotalForSelectedItems = DSum("([Cost] + ([Cost] * [TaxRate]) + [DeliveryCost])", "tblItemInfo", "[Category] = cboSelectCategory.Value")

but it won't work. Any help would be greatly appreciated.
 
Old April 9th, 2010, 08:21 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Code:
txtTotalForSelectedItems = DSum("([Cost] + ([Cost] * [TaxRate]) + [DeliveryCost])", "tblItemInfo", "[Category] = '" & Me.cboSelectCategory & "'")
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
 
Old April 10th, 2010, 06:06 PM
Authorized User
Points: 71, Level: 1
Points: 71, Level: 1 Points: 71, Level: 1 Points: 71, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Default Specifying the value of a combo box in a DSum expression

Thank you. This works. I couldn't quite get the syntax just right.
 
Old April 12th, 2010, 08:52 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

You're quite welcome. Glad I could help.

Just as a general FYI, when writing criteria for boolean (true/false), numbers, strings, and dates, the syntax requires delimiters for strings and dates.

Boolean & numbers use nothing.

Code:
x = DLookUp("[MyField]", "MyTable", "[OtherField] = " & Me.txtTextbox
Strings use apostrophes (or "single quotes").

Code:
x = DLookUp("[MyField]", "MyTable", "[OtherField] = '" & Me.txtTextbox & "'"
Dates use a pound sign (or number sign or cross-hatch)

Code:
x = DLookUp("[MyField]", "MyTable", "[OtherField] = #" & Me.txtTextbox & "#"
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division




Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Combo box to display items from parent combo box Gini Visual Studio 2008 0 June 18th, 2008 12:30 AM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.