Computer Learning Zone CLZ Access Excel Word Windows

A good education is a foundation for a better future.

-Elizabeth Warren
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
DoCmdRunSQL
alberto prado 

3 years ago
hello, I have been driving myself crazy with the syntax below. It looks simple but I have not been able to get it to work. I have a form with 2 unbound text boxes FirstRecordL and LastRecordL. I want the user to input the range for deleting records in those 2 boxes. then there is a command btn in that same form with the onclick event that will execute the SQL reading the values from those 2 text boxes.


Private Sub RunSQL_Click()

DoCmd.RunSQL ("DELETE FROM CTRTable " & _
              "WHERE [ctr #] >='" & Me.FirstRecordL & "' AND [CTR #] <='" & Me.LastRecordL & "'")

End Sub

could you please help me figure out how to make it work. or any study guide for the " and ' when doing those things? I know the issue is in there because when I use

DoCmd.RunSQL ("DELETE FROM CTRTable ") it deletes everything without issues. so, I know I have an error with the where condition.

it also works when I manually hardcode the number.
DoCmd.RunSQL ("DELETE FROM CTRTable where [ctr #] = 123")


regards,

prado


Kevin Robertson  @Reply  
          
3 years ago
Is [ctr #] a number field? If so you don't need the quotes around the field names. You only need the quotes for text fields.
Scott Axton  @Reply  
        
3 years ago
Alberto,
I don't know if this is a db that you have in production or it is one that is still in development.

I highly recommend that you change your field name from ctr # to something different.
1. You should not have spaces in your field names.
2. the # symbol is a special reserved character used in signifying dates.
Even though you have square brackets surrounding the field - [ctr #] - you are just asking for problems down the line by not changing it sooner than later.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor 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/7/2026 12:48:44 AM. PLT: 1s