Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Syntax for Insert Into
John Lucas III 
      
4 years ago
I have an unbound form that I use to add records to a table. I am just using the name of the field in the values() list without any """" or & and it seems to work fine. Is there a problem with this syntax?

    DoCmd.RunSQL "insert into Patient2 (LastName, FirstName, MiddleInitial, SSN, MRN, DOB, GenderID, RaceID, HispanicorLatino)" & _
            "values (LastName, FirstName, MiddleInitial, SSN, MRN, DOB, GenderID, RaceID, HispanicorLatino)"
Adam Schwanz  @Reply  
           
4 years ago
I would think you would need quotations and concatenation but if you say its working somehow just go with it. If it aint broke don't fix it right?
John Lucas III OP  @Reply  
      
4 years ago

Richard Rost  @Reply  
          
4 years ago
That method will work... until it doesn't. :)
John Lucas III OP  @Reply  
      
4 years ago
Under what circumstances would this fail? The syntax is so much easier than all the "" and &s.
Adam Schwanz  @Reply  
           
4 years ago
It's not supposed to work, some combination of situations is allowing it to read what you're telling it to do like that, but any kind of outside poke could bring the walls down. Whether that be changing a word/field or even something outside of access like a windows or office update could knock some sense into it and make it start to error. It's not long term reliable.
Richard Rost  @Reply  
          
4 years ago
It will sometimes work if you say:

CustomerID = DLookup("CustomerID","CustomerT","OrderID=OrderID")

Until Access can't figure out what you mean by "OrderID=OrderID". If it can find the OrderID field on the current form, then you're usually golden. However, sometimes, it can't. I don't have an exact when/where/how/why for this, but in my nearly 30 years of experience with Access, I know it's almost always better to say:

CustomerID = DLookup("CustomerID","CustomerT","OrderID=" & OrderID)

So that you EXPLICITLY send DLookup the value you want and not a field name. The same goes for SQL statements. You're sending field names, not values. So, like I said, your code will work... until it doesn't. :)

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

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: 7/26/2026 6:55:36 PM. PLT: 0s