Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA CODE FOR ACCESS

Status
Not open for further replies.

dirkB3

Programmer
Jun 9, 2003
1
ZA
Hi

Can you help me to solve the following problem with VBA code?
I am using access 2000 and want the program to replace all the records of one field with the same data (for example, all the records must have the same City name in the City field)
I don’t want to use the find and replace or update query.
I want a user to type the new City name in using a form and the program must then replace, updated all the records in the City field with the new City name typed in by the user. The existing data to be replaced also have the same name.

 
if you had 2 text boxes (or anything similar would do).

The first had the original name, and the second has the new name.


The first textbox is called textbox1.
The second textbox is called textbox2.
A button to update the field names.

A Table named "table" and a field named "city".

When the button is clicked the following code gets executed.

DoCmd.RunSQL "UPDATE
SET
.city = '" & textbox2 & "' WHERE table.city='" & textbox1 & "';"


David Pimental
(US, Oh)
dpimental@checkfree.com
 
Updating Table with Query?

****ERROR: DATA TYPE ERROR IN CRITERIA EXPRESSION****

Can anyone tell me what is wrong with the code below ?
OBJECT = TABLE
Object_Description = Field I want to add from text box
Object_Id = Primary Key determined by a variable

CODE
--------------------------------------------
Dim intMax
intMax = DMax("Object_ID", "Object") + 1

DoCmd.RunSQL "UPDATE [OBJECT] SET [OBJECT].Object_Description = '" & txtoverlaydescription & "' WHERE OBJECT.Object_id='" & intMax & "';"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top