Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Setting a Textbox Control Source with VBA
Gary Becker 
     
11 months ago
I have a textbox called LaborJTD on a form. It's controlsource is a Dsum. I added a button on the form and would like to use the Click event to change the ControlSource of that textbox. Here is the code that I thought should work:

Private Sub AllLaborBtn_Click()

    LaborJTD.ControlSource = DSum("Amount", "JCTransactions", "(Transaction_Type= ""PR Cost"" OR Transaction_Type= ""JC Cost"") AND CJobNumber =  """ & [JobNumber] & """ AND Category =  [Type] ")

End Sub

I get a #Name? error as if it doesn't know what or where the textbox is.
Kevin Robertson  @Reply  
          
11 months ago
The Control Source (when set in VBA) should be in quotes and start with an equals sign.
Gary Becker OP  @Reply  
     
11 months ago
Like how? This doesn't work:
LaborJTD.ControlSource = "=DSum("Amount", "JCTransa ...."
It gives a compile error 'Expected: end of statement'
I can understand the logic--actually just trying to place a text string in there for the control source. Just can't figure out exactly how to make it work.
Gary Becker OP  @Reply  
     
11 months ago
I figured it out. I has to be like this:

LaborJTD.ControlSource = "=" & DSum("Amount", "JCTransactions", "(Transact ......

Thanks for your help. So many different ways to put the Legos together. Urrrr
Kevin Robertson  @Reply  
          
11 months ago
Here is an example:

OrderTotal.ControlSource = "=Nz(DSum(""ExtPrice"", ""OrderDetailQ"", ""CustomerID="" & CustomerID),0)"

This gives the same result:

OrderTotal = Nz(DSum("ExtPrice", "OrderDetailQ", "CustomerID=" & CustomerID), 0)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/2/2026 7:11:13 AM. PLT: 1s