473,382 Members | 1,526 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,382 software developers and data experts.

Updating table data with SQL statement

10
I am trying to update data in a table named tblTest using an unbound form and SQL statement. I will type the data in unbound text boxes on the form. Then I will use those data in SQL statement and finally that SQL will update the data in the table. All fields in the table are of Short Text format except the ID field which is Autonumber.
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnUpdate_Click()
  2.     Dim sql As String
  3.     Dim A As Database
  4.     Dim rCount As Integer
  5.     Set A = CurrentDb()
  6.     sql = "UPDATE tblTest SET SRoll = " & Me!txtSRoll & ", SName = " & Me!txtSName & " WHERE ID = " & Me!txtID & ""
  7.     A.Execute sql, dbFailOnError
  8.     rCount = A.RecordsAffected
  9.     If rCount > 0 Then
  10.         MsgBox "Contact updated"
  11.     End If
  12. End Sub
SRoll and SName are two fields on the table.
txtSRoll, txtSName, txtID are text boxes and btnUpdate is a command button on the form.
The above code gives me error. Am I missing something??
Note: Using bound forms is a crime in this project.
Jan 3 '18 #1

✓ answered by twinnyfo

rawled,

I did get a chance to try your code, and it looks like you have forgotten the quotes around your text variables.

Line 6 should look like this:
Expand|Select|Wrap|Line Numbers
  1.     sql = "UPDATE tblTest " & _
  2.         "SET SRoll = '" & Me!txtSRoll & _
  3.         "', SName = '" & Me!txtSName & "' " & _
  4.         "WHERE ID = " & Me!txtID
All should work well after this.

4 1760
twinnyfo
3,653 Expert Mod 2GB
rawled,

What is the error that you receive upon execution? And, where does the error occur (what line)? That might help us direct our help.
Jan 3 '18 #2
twinnyfo
3,653 Expert Mod 2GB
rawled,

I did get a chance to try your code, and it looks like you have forgotten the quotes around your text variables.

Line 6 should look like this:
Expand|Select|Wrap|Line Numbers
  1.     sql = "UPDATE tblTest " & _
  2.         "SET SRoll = '" & Me!txtSRoll & _
  3.         "', SName = '" & Me!txtSName & "' " & _
  4.         "WHERE ID = " & Me!txtID
All should work well after this.
Jan 3 '18 #3
rawled
10
Thanks twinnyfo.
Looks like I messed up with the quotes. It works fine now. And there will be two double quotes at the end of the sql statement... Cheers!!
Jan 4 '18 #4
twinnyfo
3,653 Expert Mod 2GB
Glad I could hepp! I was able to have success with this SQL statement without the double quotes at the end. In terms of strings, the empty double quotes adds nothing to the string, so I do not believe it is required.
Jan 4 '18 #5

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

Similar topics

1
by: Simon | last post by:
Hi, Can anybody tell me if it is possible to return a table data type (as opposed to a temporary table) from a stored procedure. I am currently studying for 70-229 using the Thomas Moore book...
2
by: harry | last post by:
Hi All ! I open a table in Query Analyzer by right clicking on it and selecting 'Open' and when the data is displayed in the view pane I would like to be able to edit it. It seems however that...
2
by: ssb | last post by:
Hello, Am interested in knowing, how MS-access stores data internally... When I create a table and load records into it, I dont find any "data file" being created that possibles stores my...
1
by: stabbert | last post by:
We are on DB2 UDB 8.2.2 on AIX. I know this question has been asked many times on the ng but I am just not finding a real good answer. I need to be able to not only determine existing table data...
2
by: News East | last post by:
I have an existing SQL 7 server named HHARBR. HHARBR has a database named SPR with a table named "reportname" in it, the table has the name HHARBR embedded the table data. I migrated the HHARBR...
4
by: Jan | last post by:
Have an SQL create/import script. Running this on SQL would make it create a table with some values. Can Access2003 somehow use such and SQL script? I went into SQL query view to try it out, but...
2
idsanjeev
by: idsanjeev | last post by:
hello guys how can fixed the table data which display if the word can not be completed in fixed table column then bareak it in new line not expend the column width like when using this table...
0
by: neweldho982 | last post by:
Hello Thanks a lot for your help. Our DS people would like to remove the table data by calling a function (can be any other objects as well) in a SELECT query. SELECT...
1
by: vishakha | last post by:
Hi.. I m using sql server standard edition. I want to copy table data of 's1' from 'test1.dbo' into another table 's2' which is exist in another database 'test2.dbo'. I m using import option to...
0
by: maxcad | last post by:
I am a novice so be patient with me. I started a simple form and dragged the datasource onto the form and VB created everything nicely including the navigation bar. The problem is that the save...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.