Change a field value in a record in a table from an unbound form

G

Guest

I am trying to update a field value in a record in a table from a form that
is not bound to the table. Can anyone suggest a way to go to a specific
record in a table and change the value of a field from a form that is bound
to another table.
Thanks in advance.

Michalis
 
G

Guest

You can use an update SQL, to update a specific field in a specific record

Try this
' If the field you are using are string add a single quote before and after
the parameter
DoCmd.RunSQL "UPDATE tblTableName SET
tblTableName.Field1Name = '" & ParamValue1 & "' WHERE
tblTableName.Field2Name= '" & ParamValue2 & "'"

' If the field you are using are number drop the single quote before and
after the parameter
DoCmd.RunSQL "UPDATE tblTableName SET
tblTableName.Field1Name = " & ParamValue1 & " WHERE tblTableName.Field2Name=
" & ParamValue2

' If the field you are using are date add the # symbol before and after the
parameter
DoCmd.RunSQL "UPDATE tblTableName SET
tblTableName.Field1Name = #" & ParamValue1 & "# WHERE
tblTableName.Field2Name= #" & ParamValue2 & "#"
 
G

Guest

Thanks a lot for your reply Ofer. The problem is that I don't always know
what the value of ParamValue1 but I know the value of ParamValue2. I was
thinking of using a command similar to DLookup. If there is one.
 
G

Guest

You can use dlookup, instead of ParamValue2

the parameter
DoCmd.RunSQL "UPDATE tblTableName SET
tblTableName.Field1Name = '" & Dlookup("FieldName","Tablename","Criteria") &
"' WHERE
tblTableName.Field2Name= '" & ParamValue2 & "'"
 

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