Solved

syntax of ADODB.recordset's UPDATE with variable used in FIELD and VALUE argument?

Posted on 2007-11-30
3
432 Views
Last Modified: 2008-02-07
I want to use ADODB.RECORDSET 's UPDATE method but I need to use variable in the FIELDS AND VALUES argument.
  'recordset.update fields,values
0
Comment
Question by:isischen
[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
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20387395
recordset.update will use the fields collection actual vs retrieved values, so, it will rather work like this:

recordset.fields("field").value = "value"
...
recordset.update

and adodb will generate and run the sql for you.

if fields and values are 2 collections/array/... you "just" need to loop through them and make the line to assign the value "dynamic"...
0
 
LVL 39

Expert Comment

by:stevbe
ID: 20388231
Dim strFile As String
Dim varValue As Variant

'set your field and value variables ...

'then pass them in like this ...
rst.Fields(strField).Value = varValue
rst.Update

Steve
0
 
LVL 39

Accepted Solution

by:
stevbe earned 250 total points
ID: 20388236
ack ,... typos ...

Dim strField As String
Dim varValue As Variant

'set your field and value variables ...
strField = "CustomerName"
varValue = "Microsoft"

'then pass them in like this ...
rst.Fields(strField).Value = varValue
rst.Update

Steve
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

630 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