Solved

How to use Docmd.RunSQL

Posted on 2003-11-20
4
17,623 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now