0
votes

can someone please help me with the following query

i need to update a datasheet (table) in access through a form:

i will have something like this

SQLtext = "update table1 set column1="sometext" where column2=textbox1.value"
DoCmd.RunSQL SQLtext

is this possible to do?

i have a textbox on a form and when i click a button on that form i want to update data in the datasheet where one of the columns is equal to the value property of a textbox

thank you!

1
Consider using CurrentDb.Execute with dbFailOnError instead of DoCmd.RunSQL. For another approach, look at David Fenton's SQLRun function: eggheadcafe.com/software/aspnet/35365281/… - HansUp
A datasheet and a table are not by any means the same thing. A datasheet is a user interface object that can represent be a table, a saved QueryDef or a form. - David-W-Fenton

1 Answers

2
votes

This is what you need (note the subtle change)

SQLtext = "update table1 set column1='sometext' where column2='" & textbox1.value & "'"
DoCmd.RunSQL SQLtext

Note: For production code you will want to escape out any single quotes in the textbox1.value string using the string replace function, otherwise you will get a SQL error whenever a user types a single quote in that field.