Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use Docmd.RunSQL

Posted on 2003-11-20
4
Medium Priority
?
17,662 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 600 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 150 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

926 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