Solved

How to use Docmd.RunSQL

Posted on 2003-11-20
4
17,633 Views
Last Modified: 2012-06-21
I would like to update a field to an inputed value on a combo box using the Domcd.runsql function in VB.


0
Comment
Question by:syenite
[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
4 Comments
 
LVL 2

Expert Comment

by:Team929
ID: 9792780
You'll need to be a bit more specific. If I got you correctly, you want to take a selected value (by the user) from a combo box and want to update (not insert) it to a table, via docmd.runsql? It'd be easier to help if you could tell us a little more about what it is you are doing.
0
 

Expert Comment

by:erazo
ID: 9793097
Dim Mydb As Database
Dim strSQL As String

Set Mydb = CurrentDb

strSQL = "UPDATE tblRefuel SET odometer = " & Me!ComboBox & " WHERE VehID = " & Me!VehID
Mydb.Execute strSQL

Mydb.Close


0
 
LVL 5

Accepted Solution

by:
morpheus30 earned 200 total points
ID: 9793503
DoCmd.RunSQL is used like this:

Dim strSQL As String

strSQL = "UPDATE TableName SET FieldName = " & Me.TextBox & " WHERE IDField = " & Me.ControlWithIDValue

DoCmd.RunSQL strSQL

The DoCmd.RunSQL can ONLY be used with action queries such as INSERT, UPDATE, DELETE, CREATE TABLE, DROP TABLE, TRUNCATE TABLE, etc.  You CANNOT use it to return a recordset (i.e. SELECT statement).
0
 
LVL 2

Assisted Solution

by:thorkyl
thorkyl earned 50 total points
ID: 9798957
currentdb.execute ("UPDATE TableName SET FieldName = " & Me.TextBox & " WHERE IDField = " & Me.ControlWithIDValue)

and you dont get any warnings

or

as everyone above

Just add

docmd.setwarnings=false
DoCmd.RunSQL strSQL
docmd.setwarnings=true
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

738 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