Solved

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

Posted on 2007-11-30
3
425 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

751 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