Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use Docmd.RunSQL

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

718 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