Solved

How to use Docmd.RunSQL

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 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

24 Experts available now in Live!

Get 1:1 Help Now