Mass table changes with VB

G

Guest

if I wanted to do something (in VB) like,

if commandbutton is clicked,

filter column A in table by criteria: "X"
filter column B by criteria: "Y"

now with X and Y as filters,
change all the data in column C to "Z"

anyone know how i can do that?

Thanks~
 
M

Marshall Barton

Kaseano said:
if I wanted to do something (in VB) like,

if commandbutton is clicked,

filter column A in table by criteria: "X"
filter column B by criteria: "Y"

now with X and Y as filters,
change all the data in column C to "Z"


Be sure to test on a copy of your table:

Set db = CurrentDb()
strSQL = "UPDATE table SET [C] = 'Z' " _
& "WHERE [A] = 'X' And = 'Y' "
db.Execute strSQL, dbFailOnError
 
G

Guest

I can't seem to get any change on the table.
the code looks like,

Private Sub alertassignallcommand_Click()

Dim strSQL As String
strQuote = Chr$(34)
Set db = CurrentDb()
strSQL = "UPDATE AlertTable SET [Assigned] = 'Z'"
' & "WHERE [ILEC] = " & strQuote & Forms!SeanIn!alertILECtext & strQuote
& " And [ST] = " & strQuote & Forms!SeanIn!alertstatetext & strQuote

db.Execute strSQL, dbFailOnError
' DoCmd.RunSQL strSQL


End Sub

AlertTable is the table that the subform in the main form queries

I was hoping this code would fill the entire "Assigned" Column with 'Z'
it didn't do anything though =(

I wasn't sure what db meant either...



Marshall Barton said:
Kaseano said:
if I wanted to do something (in VB) like,

if commandbutton is clicked,

filter column A in table by criteria: "X"
filter column B by criteria: "Y"

now with X and Y as filters,
change all the data in column C to "Z"


Be sure to test on a copy of your table:

Set db = CurrentDb()
strSQL = "UPDATE table SET [C] = 'Z' " _
& "WHERE [A] = 'X' And = 'Y' "
db.Execute strSQL, dbFailOnError
 
M

Marshall Barton

Seems like you tried to cram the entire SQL statement in one
line and then hit the enter key when it got too long.

Private Sub alertassignallcommand_Click()
Dim db As DAO.Database
Dim strSQL As String
Dim strQuote As String
strQuote = Chr$(34)
Set db = CurrentDb()
strSQL = "UPDATE AlertTable " _
& "SET [Assigned] = 'Z' " _
& "WHERE [ILEC] = " & strQuote & _
Forms!SeanIn!alertILECtext & strQuote _
& " And [ST] = " & strQuote & _
Forms!SeanIn!alertstatetext & strQuote
db.Execute strSQL, dbFailOnError
End Sub
--
Marsh
MVP [MS Access]

I can't seem to get any change on the table.
the code looks like,

Private Sub alertassignallcommand_Click()

Dim strSQL As String
strQuote = Chr$(34)
Set db = CurrentDb()
strSQL = "UPDATE AlertTable SET [Assigned] = 'Z'"
' & "WHERE [ILEC] = " & strQuote & Forms!SeanIn!alertILECtext & strQuote
& " And [ST] = " & strQuote & Forms!SeanIn!alertstatetext & strQuote

db.Execute strSQL, dbFailOnError
' DoCmd.RunSQL strSQL


End Sub

AlertTable is the table that the subform in the main form queries

I was hoping this code would fill the entire "Assigned" Column with 'Z'
it didn't do anything though =(

I wasn't sure what db meant either...


Marshall Barton said:
Be sure to test on a copy of your table:

Set db = CurrentDb()
strSQL = "UPDATE table SET [C] = 'Z' " _
& "WHERE [A] = 'X' And = 'Y' "
db.Execute strSQL, dbFailOnError
 
G

Guest

That worked, thanks MB

Marshall Barton said:
Seems like you tried to cram the entire SQL statement in one
line and then hit the enter key when it got too long.

Private Sub alertassignallcommand_Click()
Dim db As DAO.Database
Dim strSQL As String
Dim strQuote As String
strQuote = Chr$(34)
Set db = CurrentDb()
strSQL = "UPDATE AlertTable " _
& "SET [Assigned] = 'Z' " _
& "WHERE [ILEC] = " & strQuote & _
Forms!SeanIn!alertILECtext & strQuote _
& " And [ST] = " & strQuote & _
Forms!SeanIn!alertstatetext & strQuote
db.Execute strSQL, dbFailOnError
End Sub
--
Marsh
MVP [MS Access]

I can't seem to get any change on the table.
the code looks like,

Private Sub alertassignallcommand_Click()

Dim strSQL As String
strQuote = Chr$(34)
Set db = CurrentDb()
strSQL = "UPDATE AlertTable SET [Assigned] = 'Z'"
' & "WHERE [ILEC] = " & strQuote & Forms!SeanIn!alertILECtext & strQuote
& " And [ST] = " & strQuote & Forms!SeanIn!alertstatetext & strQuote

db.Execute strSQL, dbFailOnError
' DoCmd.RunSQL strSQL


End Sub

AlertTable is the table that the subform in the main form queries

I was hoping this code would fill the entire "Assigned" Column with 'Z'
it didn't do anything though =(

I wasn't sure what db meant either...

Kaseano wrote:
if I wanted to do something (in VB) like,

if commandbutton is clicked,

filter column A in table by criteria: "X"
filter column B by criteria: "Y"

now with X and Y as filters,
change all the data in column C to "Z"

Marshall Barton said:
Be sure to test on a copy of your table:

Set db = CurrentDb()
strSQL = "UPDATE table SET [C] = 'Z' " _
& "WHERE [A] = 'X' And = 'Y' "
db.Execute strSQL, dbFailOnError

 

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