Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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.
Reply With Quote
  #4 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.