Computer Learning Zone CLZ Access Excel Word Windows

The downside of my celebrity is that I cannot go anywhere in the world without being recognized. It is not enough for me to wear dark sunglasses and a wig. The wheelchair gives me away.

-Stephen Hawking
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visual Basic Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
VBA variables in SQL
tim 

16 years ago
Hi,

I  am burning my brain up trying to do something I thought would be so simple that I must be the simple one – I want to use an InputBox in VBA 6.5 (in Access 2002) to accept a piece of information from the user of a form. I then want to use an SQL statement in the VBA to be able to insert the information into a table. I have tried every combination of single and double quotes, brackets and parenthesise around the variable “NewTestingActivity” in the SQL statement, but the best I can achieve is a prompt box to pop up with the Sub below. To your experienced eye it will be obvious what this novice is doing wrong…

Dim NewTestingActivity As String

Private Sub for_all_leas_Click()
NewTestingActivity = InputBox("Please enter the name of the new Test Activity:", "New Test Activity")
DoCmd.RunSQL "INSERT INTO TestingActivities (TestingActivityDescription) VALUES (NewTestingActivity);"

Many thanks in hope

Tim


Answer from Richard Rost:

Try:

DoCmd.RunSQL "INSERT INTO TestingActivities (TestingActivityDescription) VALUES (" & NewTestingActivity & ");"

And if that doesn't work, add quotes:

DoCmd.RunSQL "INSERT INTO TestingActivities (TestingActivityDescription) VALUES (""" & NewTestingActivity & """);"

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visual Basic 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/22/2026 9:24:37 AM. PLT: 1s