There is no canned function like DLOOKUP, but you could use:
Public Function fnPut(Fieldname as string, Tablename as string, _
SomeValue as Variant, Optional Criteria as
Variant = NULL) as boolean
Dim strSQL as string
Dim rs as DAO.Recordset
On Error GoTo fnPutError
strSQL = "SELECT [" & Fieldname & "] " _
& "FROM [" & Tablename & "] " _
& ("WHERE " + Criteria)
set rs = Currentdb.openrecordset (strsql, , dbfailonerror)
While not rs.eof
rs.edit
rs(Fieldname) = SomeValue
rs.update
rs.movenext
Wend
fnPut = true
fnPutExit:
if not rs is nothing then
rs.close
set rs = nothing
endif
Exit Function
fnPutError:
msgbox err.number & err.description, vbInformation + vbOkOnly, "Error:
fnPut"
fnPut = false
Resume fnPutExit
End sub
I use a function that looks like this, although I don't have access to it
at the moment (this is air code, so you might run into a bug or two).
While this is slower than an UPDATE statement especially if the criteria
returns multiple values, you avoid having to deal with making sure you
have your SomeValue parameter in the right format. This will return a
true if the update worked and a false if an error was generated.
HTH
Dale
Bill said:
From time-to-time I find it useful to use
DLookup to obtain a value from one of
a table's fields. Is there there the reverse
of that? I.e., save a value into a table
field with a criteria of the record's ID?
I looked in SQL, but I have the idea
I missed something.
Bill