473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Using DoCmd.RunSQL to Update Table

134 100+
Hi, I try to run the below statement, it alway popup a box and prompt me to input the unit, what wrong with my statement. There is no sub form.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "Update tblvndprod set unit= " & Me.UnitMeasurement & " where productID=" & Me.ProductID
  2.  
Dec 18 '07 #1
4 28716
Rabbit
12,516 Expert Mod 8TB
Please use code tags.

You need to delimit your UnitMeasurement as a string. Without quotes, it will think it's a variable.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "Update tblvndprod set unit= '" & Me.UnitMeasurement & "' where productID=" & Me.ProductID
  2.  
Dec 18 '07 #2
jamesnkk
134 100+
Please use code tags.

You need to delimit your UnitMeasurement as a string. Without quotes, it will think it's a variable.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "Update tblvndprod set unit= '" & Me.UnitMeasurement & "' where productID=" & Me.ProductID
  2.  
Wow ! it work !, thanks a millions, btw I really don;t understand the single quote and the double quote combination, would you mind explain a little or any website that I could understand a bit more on the single and double quote combination.
Dec 18 '07 #3
Rabbit
12,516 Expert Mod 8TB
RunSQL requires a string. To delimit something as a string, you surround it with either double quotes or single quotes.

Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM Table1"
  2. 'SELECT * FROM Table1'
However, what the SQL processor sees it without the quotes.
But, when the SQL engine is processing the statement, if it's expecting a string, then you have to tell it that it is a string by surrounding it with either single quotes or double quotes.

However, if you are already delineating a string using one of the quotes, then if you need to delineate another string, you need to use the other quote or double up on the quote.

All of the below are syntactically correct.
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM Table1 WHERE Field1 = 'x'"
  2. 'SELECT * FROM Table1 WHERE Field1 = "x"'
  3. "SELECT * FROM Table1 WHERE Field1 = ""x"""
  4. 'SELECT * FROM Table1 WHERE Field1 = ''x'''
  5.  
RunSQL gets:
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM Table1 WHERE Field1 = 'x'"
But RunSQL uses the SQL engine. The SQL engine processes:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Table1 WHERE Field1 = 'x'
  2.  
So without the quotes to tell the engine that 'x' is actually a string and not a variable, then it will try to find that variable named x.
Dec 18 '07 #4
jamesnkk
134 100+
RunSQL requires a string. To delimit something as a string, you surround it with either double quotes or single quotes.

Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM Table1"
  2. 'SELECT * FROM Table1'
However, what the SQL processor sees it without the quotes.
But, when the SQL engine is processing the statement, if it's expecting a string, then you have to tell it that it is a string by surrounding it with either single quotes or double quotes.

However, if you are already delineating a string using one of the quotes, then if you need to delineate another string, you need to use the other quote or double up on the quote.

All of the below are syntactically correct.
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM Table1 WHERE Field1 = 'x'"
  2. 'SELECT * FROM Table1 WHERE Field1 = "x"'
  3. "SELECT * FROM Table1 WHERE Field1 = ""x"""
  4. 'SELECT * FROM Table1 WHERE Field1 = ''x'''
  5.  
RunSQL gets:
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM Table1 WHERE Field1 = 'x'"
But RunSQL uses the SQL engine. The SQL engine processes:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Table1 WHERE Field1 = 'x'
  2.  
So without the quotes to tell the engine that 'x' is actually a string and not a variable, then it will try to find that variable named x.

Thank you so much for writing a wonderful and a careful though explanation, I will try to figure out
Dec 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ilan Sebba | last post by:
When it comes to adding records in related tables, Access is really smart. But when I try to do the same using ADO, I am really stupid. Say I have two parent tables (eg Course, Student) and one...
4
by: Rotsj | last post by:
Hi, i try to execute an update query from within a form, but i get the message: run time error '3144'. Syntax error on the update statement when i try something like this: DoCmd.RunSQL...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
6
by: David | last post by:
I am trying to insert an employee number into the EmpNbr field in my main table from a form where I add a new employee to my employee table. I was hoping this command would work, but it isn't. ...
2
by: mlevit | last post by:
Hey all, I'm trying to update a table using sql with todays date. I use this, Dim todaysDate As Date todaysDate = Date
1
by: afromanam | last post by:
Hello, Good morning, I have a question, hope someone can help me. I have a table with say, 5 columns, each named A,B,C,D,E The table was imported from Excel, so picture please this:
1
by: natural | last post by:
Good Afternoon I have an option grou[ and on the after update i would like to provide the user with a msgbox, and then action placed my docmd.setwarnings false everywhere, but i still get my...
2
by: Constantine AI | last post by:
I am wanting to import CSV files into Access, which isn't a problem at the moment the code i have is as follows: Dim strSQL As String Dim CSVTable As String Dim FilePath As String Dim Result As...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.