Solved

INSERT INTO statement not working - ACCESS 2010 database

Posted on 2013-12-12
2
467 Views
Last Modified: 2013-12-12
I just do not know what is wrong with this statement.

    DoCmd.RunSQL "INSERT INTO tblIDNums(MachineUserID, MachineID) " & _
        "VALUES(" & fntVBUserName & ", " & fntMachineName() & " "
0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
gozoliet earned 500 total points
ID: 39715315
Your string variables need to be contained within quotes and closing parenthesis missing:

DoCmd.RunSQL "INSERT INTO tblIDNums(MachineUserID, MachineID) " & _
        "VALUES('" & fntVBUserName & "', '" & fntMachineName() & "') "


Note I added a single quote before/after the variables. If you have single quotes in your variables you need to escape or you may run into problems.

Better solution is to use a querydef with parameters so that you don't have to worry about special characters in the string.
0
 

Author Closing Comment

by:ssmith94015
ID: 39715386
went the querydef route, was better.

Sandra
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Database maintenance 36 110
Parameter Query 33 52
VBA Delete sql "Too Few Parameters" 8 24
Installing the 2016 Access runtime with office home and business 6 17
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question