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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update simplified 1

Status
Not open for further replies.

primerov

Technical User
Aug 16, 2002
160
0
0
BG
I want to build a function that sets chosen fields to 0.
I want to simplify my function since i have to repeat and and the same line
code.
I am doing now the following


Public function ClearFields()
' set the field Field2 to 0
Dim sqlField2 as string
sqlField2 = " Update products SET Field2 = 0"
CurrentDb.Execute SqlField2


' set the field Field4 to 0
Dim sqlField5 as string
sqlField5 = " Update products SET Field5 = 0"
CurrentDb.Execute SqlField5

etc etc I have 5 more fields to set to 0"

Is there any way to simplify my code, put the fields into brackets and just
contain the function into one or two lines ?





 
Yes:

Code:
Dim sqlString As String

sqlString = " Update products SET Field2 = 0, Field3 = 0, Field4 = 0, Field5 = 0"
CurrentDb.Execute sqlString

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top