Ho Wai Yan Arthur
Ho Wai Yan Arthur

Reputation: 21

Replacing String for entire Column

I am new to MS ACCESS & SQL

I am trying to replace all the "[" & "]" within the table. Am I suppose to use REPLACE command or should Select & Loop through the Table?

Either way, I don't know how to write it in VBA. Thanks for help

I tried this, and it is not working

DoCmd.RunSQL "SELECT REPLACE" & "(StudentFirstName,'[','')" & "FROM StudentName"

See the Table Structure:

figure 1

Upvotes: 0

Views: 104

Answers (1)

I'm Not A Robot
I'm Not A Robot

Reputation: 294

Just run an UPDATE query with REPLACE() function:

UPDATE tableName SET fieldName = REPLACE(fieldName, '[', '')

and than with the other bracket:

UPDATE tableName SET fieldName = REPLACE(fieldName, ']', '')

If you want to use in your vba code:

Docmd.RunSQL "UPDATE tableName SET fieldName = REPLACE(fieldName, '[', '')"
Docmd.RunSQL "UPDATE tableName SET fieldName = REPLACE(fieldName, ']', '')"

Remember: SELECT it's used only for VIEW data and not for edit. If you want to EDIT data in your table you need to use UPDATE.

Upvotes: 1

Related Questions