Need to update a field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to update a field called Time for a SSN.
Here is the query that I have:
UPDATE Main SET Main.SSN = [newSSN], Main.[Time] = Now();
Does that look right?

But how do I update it using code? SSN is a text box on the form.
 
If I understood you then you want to update the field Time where the field
SSN = the field newSSN in the form.
Using VBA

Docmd.RunSql "UPDATE Main SET Main.[Time] = Now() WHERE Main.SSN = " &
Forms![FormName]![newSSN]
' incase SSN is number type
============================================
Docmd.RunSql "UPDATE Main SET Main.[Time] = Now() WHERE Main.SSN = '" &
Forms![FormName]![newSSN] & "'"
' incase SSN is string type
============================================
The SQL you gave will update all the fields in the table, and I'm not sure
if that what you want to do, but if that what you are trying to do, then

' If SSN string
Docmd.RunSql "UPDATE Main SET Main.SSN = '" & Forms![FormName]![newSSN] &
"', Main.[Time] = Now()"

' If SSN Number
Docmd.RunSql "UPDATE Main SET Main.SSN = " & Forms![FormName]![newSSN] & ",
Main.[Time] = Now()"
 
One more thing, you better change the name of the field Time, it a reserved
name in Access
 
Yes you were right I only wanted to update one SSN's Time field. I will
also change the field name to something other than Time.


Ofer said:
One more thing, you better change the name of the field Time, it a reserved
name in Access

pokdbz said:
I need to update a field called Time for a SSN.
Here is the query that I have:
UPDATE Main SET Main.SSN = [newSSN], Main.[Time] = Now();
Does that look right?

But how do I update it using code? SSN is a text box on the form.
 
there is something wrong with this statement.
Docmd.RunSql "UPDATE Main SET Main.[Time] = Now() WHERE Main.SSN = " &
Forms![FormName]![newSSN]

when I put it into the VB code it comes up like it is commented so there is
an error somewhere

When I put this into the sql query it says syntax error:
UPDATE Main SET Main.[Time] = Now() WHERE Main.SSN = " &
Forms![FormName]![newSSN]



Ofer said:
If I understood you then you want to update the field Time where the field
SSN = the field newSSN in the form.
Using VBA

Docmd.RunSql "UPDATE Main SET Main.[Time] = Now() WHERE Main.SSN = " &
Forms![FormName]![newSSN]
' incase SSN is number type
============================================
Docmd.RunSql "UPDATE Main SET Main.[Time] = Now() WHERE Main.SSN = '" &
Forms![FormName]![newSSN] & "'"
' incase SSN is string type
============================================
The SQL you gave will update all the fields in the table, and I'm not sure
if that what you want to do, but if that what you are trying to do, then

' If SSN string
Docmd.RunSql "UPDATE Main SET Main.SSN = '" & Forms![FormName]![newSSN] &
"', Main.[Time] = Now()"

' If SSN Number
Docmd.RunSql "UPDATE Main SET Main.SSN = " & Forms![FormName]![newSSN] & ",
Main.[Time] = Now()"


pokdbz said:
I need to update a field called Time for a SSN.
Here is the query that I have:
UPDATE Main SET Main.SSN = [newSSN], Main.[Time] = Now();
Does that look right?

But how do I update it using code? SSN is a text box on the form.
 
I got it stupid mistake by me.

Do you know how to turn off the warning that it is updating the field?
 
Set the warnings to False

Docmd.setWarnings False
Docmd.RunSql ""
Docmd.setWarnings True

' Don't forget to set it back to True

I got it stupid mistake by me.

Do you know how to turn off the warning that it is updating the field?
I need to update a field called Time for a SSN.
Here is the query that I have:
UPDATE Main SET Main.SSN = [newSSN], Main.[Time] = Now();
Does that look right?

But how do I update it using code? SSN is a text box on the form.
 
You can also turn it off permanently - Tools:Options:Edit/Find Uncheck
Confirm Action Queries



pokdbz said:
I got it stupid mistake by me.

Do you know how to turn off the warning that it is updating the field?

pokdbz said:
I need to update a field called Time for a SSN.
Here is the query that I have:
UPDATE Main SET Main.SSN = [newSSN], Main.[Time] = Now();
Does that look right?

But how do I update it using code? SSN is a text box on the form.
 
Back
Top