UID = ID in my table that is an autonumber.
So I assume, that to be correct I must use:
DoCmd.RunSQL "UPDATE tblDatabase SET User1='" &
[TempVars]![varUtilizator]
&
" WHERE UID = " Me.UID
But there is a problem when I enter Me.UID and I run the form. Gives me
an
error. I am getting a random error. Sometime is working, sometimes is
not.
I must be doing something wrong with my code.
:
DoCmd.RunSQL "UPDATE tblDatabase SET User1='" &
[TempVars]![varUtilizator] & "' WHERE UID = ' " & Me.UID & " ' "
This looks almost correct. You have an extra set of single quotes in
the
where statement. Change it to this instead:
DoCmd.RunSQL "UPDATE tblDatabase SET User1='" &
[TempVars]![varUtilizator] &
" WHERE UID = '" & Me.UID & "'"
Be sure to include the space between the quote and WHERE, it needs to
be
there. As for the ' " combinations surrounding Me.UID, I took those
out,
though it makes it more difficult to read, those spaces cannot be
there.
That should do it, assuming your field name is UID, and your UID
datatype
is
a text data. If it is number, you need to go about it a little
differently
and remove the quotes around the value...
DoCmd.RunSQL "UPDATE tblDatabase SET User1='" &
[TempVars]![varUtilizator] &
" WHERE UID = " Me.UID
hth
--
Jack Leach
www.tristatemachine.com
"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
:
Ok, and I am trying to do this:
Dim varReturn As Variant
varReturn = DLookup("[User1]", "tblDatabase", "[UID]=" & Me.UID)
If IsNull(varReturn) Then
DoCmd.RunSQL "UPDATE tblDatabase SET User1='" &
[TempVars]![varUtilizator] & "' WHERE UID = ' " & Me.UID & " ' "
or even
DoCmd.RunSQL "UPDATE tblDatabase SET User1='" &
[TempVars]![varUtilizator] &
"' WHERE UID =UID "
That changes the whole table, not just the record I editing.
Thanks.
:
You need to include a Where clause, otherwise the entire table
gets
updated.
UPDATE tblDatabase Set User1='" & [TempVars]![varUser] & "' " & _
"WHERE [SomeIDField] = SomeCriteria"
hth
--
Jack Leach
www.tristatemachine.com
"I haven''t failed, I''ve found ten thousand ways that don''t
work."
-Thomas Edison (1847-1931)
:
Dim varReturn As Variant
varReturn = DLookup("[User1]", "tblDatabase", "[UID]= " &
Me.UID)
If IsNull(varReturn) Then
DoCmd.RunSQL "UPDATE tblDatabase SET User1='" &
[TempVars]![varUser] & "'"
End If
The following command line is updating me the whole table,
instead
of
updating only the selected record.
How can I do to just modify the current record?