Domain Aggregate Functions

D

David

I have been using the Dlookup type functions quite a bit with my database,
but I need to now write a data back to a table. Is there a domain aggregate
type command that I can use to write a value to a table?

Thanks,

Dave
 
A

Anthony

No such thing. But--

With only one line of code you can trigger an action (Update) query like
this:

DoCmd.RunSQL ("UPDATE MyTable SET MyField = 'MyValue' WHERE MyField =
'MyCriteria'")

If you are passing the value of a variable to the "SET" field, do it like
this:

DoCmd.RunSQL ("UPDATE MyTable SET MyField = '" & MyValue & "' WHERE MyField
= 'MyCriteria'")

If you are passing a value of a NUMERIC variable to the "SET" field, do it
like this: (Leave out the ' )

DoCmd.RunSQL ("UPDATE MyTable SET MyField = " & MyValue & " WHERE MyField =
'MyCriteria'")

Good luck
 
A

Anthony

Another thing you can do.

If you want to do this repeatedly throught your project, write a function.


Sub TestMyFunction

UpdateRecord "MyTable", "MyField", MyFieldValue, "MyCriteriaField",
"MyCriteria"

End Sub

Function UpdateRecord(myTable as String, myField as String, myFieldValue as
Variant, myCriteriaField as String, myCriteria as String)

DoCmd.RunSQL ("UPDATE " & myTable & " SET [" & myField & "] = " &
iif(isnumeric(myValue),"","'") & myValue & iif(isnumeric(myValue),"","'") &
" WHERE " & _
myCriteriaField & " = " &
iif(isnumeric(myCriteria),"","'") & myCriteria &
iif(isnumeric(MyCriteria),"","'"))

End Function
 
D

David

Ok thanks Anthony. That will do the trick.


Anthony said:
Another thing you can do.

If you want to do this repeatedly throught your project, write a function.


Sub TestMyFunction

UpdateRecord "MyTable", "MyField", MyFieldValue, "MyCriteriaField",
"MyCriteria"

End Sub

Function UpdateRecord(myTable as String, myField as String, myFieldValue
as Variant, myCriteriaField as String, myCriteria as String)

DoCmd.RunSQL ("UPDATE " & myTable & " SET [" & myField & "] = " &
iif(isnumeric(myValue),"","'") & myValue & iif(isnumeric(myValue),"","'")
& " WHERE " & _
myCriteriaField & " = " &
iif(isnumeric(myCriteria),"","'") & myCriteria &
iif(isnumeric(MyCriteria),"","'"))

End Function


David said:
I have been using the Dlookup type functions quite a bit with my database,
but I need to now write a data back to a table. Is there a domain
aggregate type command that I can use to write a value to a table?

Thanks,

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top