update statement

Am using vb6, MS Access 2000 and ado. I want to update multiple values which match a certain criteria.  For example i want to update the values in txtJobTitle, txtLocation, txtDepartment, txtExtension for the user in the txtID textbox. What is the syntax? The table name is Users.
asansAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

asansAuthor Commented:
also the delete statement
Éric MoreauSenior .Net ConsultantCommented:
strSQL = "update YourTableName " & _
"SET JobTitleField = '" & replace(txtJobTitle.text, "'", "''") & "' " & _
", LocationField = '" & replace(txtLocation.text, "'", "''") & "' " & _
", DepartmentField = '" & replace(txtDepartment.text, "'", "''") & "' " & _
", ExtensionField = '" & replace(txtExtension.text, "'", "''") & "' " & _
"WHERE IDField = " & txtID.text

YourConnection.Execute strSQL


strSQL = "DELETE FROM YourTableName " & _
"WHERE IDField = " & txtID.text

YourConnection.Execute strSQL
Ryan ChongSoftware Team LeadCommented:
try like:

SQLstr = "Update Users SET "  & _
"JobTitle = '" & Replace$(txtJobTitle, "'","''") & "' , " & _
"Location= '" & Replace$(txtJobTitle, "'","''") & "' , " & _
"Department = '" & Replace$(txtJobTitle, "'","''") & "' , " & _
"Extension = '" & Replace$(txtJobTitle, "'","''") & "'  " & _
"WHERE ID = " & val(txtID)

conn.execute SQLstr

'Where conn is an ADO.Connection Object.

to delete, just try change the sql statement to as:

SQLstr = "Delete From Users WHERE ID = " & val(txtID)


Hope this helps, cheers
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Ryan ChongSoftware Team LeadCommented:
exact the same thing but mine is slower, emoreau should get the points here, cheers ;-)
asansAuthor Commented:
Emoreau, i am going to give you points. But before i do so, i am updating many tables using that code without a problem. However for one table, i get an Object required error message when i run the appl. The code

strSQL = "update YourTableName " & _
"SET JobTitleField = '" & replace(txtJobTitle.text, "'", "''") & "' " & _
", LocationField = '" & replace(txtLocation.text, "'", "''") & "' " & _
", DepartmentField = '" & replace(txtDepartment.text, "'", "''") & "' " & _
", ExtensionField = '" & replace(txtExtension.text, "'", "''") & "' " & _
"WHERE IDField = " & txtID.text
 
will be highlighted. What is the issue
Éric MoreauSenior .Net ConsultantCommented:
What is your real code? This is just MY code with dummy table name and field names.
asansAuthor Commented:
The code is......

strSQL = "UPDATE Computers " & _
  "SET ComputerType = '" & Replace(cboEComputerType.Text, "'", "''") & "' " & _
   ", Make = '" & Replace(cboEComputerMake.Text, "'", "''") & "' " & _
   ", Model = '" & Replace(cboEComputerModel.Text, "'", "''") & "' " & _
   ", HardDrive = '" & Replace(Val(txtEHDD.Text), "'", "''") & "' " & _
   ", RAM = '" & Replace(Val(txtERAM.Text), "'", "''") & "' " & _
   ", CDType = '" & Replace(cboECDType.Text, "'", "''") & "' " & _
   ", NetworkCard = '" & Replace(cboENIC.Text, "'", "''") & "' " & _
   ", MouseMake = '" & Replace(txtEMouseMake.Text, "'", "''") & "' " & _
   ", MouseS/N = '" & Replace(txtEMouseSerialNumber.Text, "'", "''") & "' " & _
   ", KeyboardMake = '" & Replace(txtEKboardMake.Text, "'", "''") & "' " & _
   ", KeyboardS/N = '" & Replace(txtEKboardSerialNumber.Text, "'", "''") & "' " & _
   ", VDUMake = '" & Replace(cboEVDUMake.Text, "'", "''") & "' " & _
   ", VDUModel = '" & Replace(txtEVDUModel.Text, "'", "''") & "' " & _
   ", VDUS/N = '" & Replace(txtEVDUSerialNumber.Text, "'", "''") & "' " & _
   ", PrinterMake = '" & Replace(cboEPrinterMake.Text, "'", "''") & "' " & _
   ", PrinterModel = '" & Replace(cboEPrinterModel.Text, "'", "''") & "' " & _
   ", PrinterS/N = '" & Replace(txtEPrinterSerialNumber.Text, "'", "''") & "' " & _
   ", ScannerMake = '" & Replace(cboEScannerMake.Text, "'", "''") & "' " & _
   ", ScannerModel = '" & Replace(txtEScannerModel.Text, "'", "''") & "' " & _
   ", ScannerS/N = '" & Replace(txtEScannerSerialNumber.Text, "'", "''") & "' " & _
   ", ModemMake = '" & Replace(cboEModemMake.Text, "'", "''") & "' " & _
   ", ModemModel = '" & Replace(txtEModemModel.Text, "'", "''") & "' " & _
   ", ModemS/N = '" & Replace(txtEModemSerialNumber.Text, "'", "''") & "' " & _
  "WHERE SerialNumber = '" & txtComputerSearchEdit & "'"
 rstConnGenericRecordset.Execute strSQL
Éric MoreauSenior .Net ConsultantCommented:
What is the datatype of rstConnGenericRecordset ? It has to be a Connection.

Also, you don't have to search for quotes into numbers. So lines like this one:
  ", RAM = '" & Replace(Val(txtERAM.Text), "'", "''") & "' " & _
Should read:
  ", RAM = " & Val(txtERAM.Text) & " " & _

Finally, one of the controls may be incorrectly spelled. Try to simplify your query (by removing many fields and re-adding them one-by-one until you find it).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongSoftware Team LeadCommented:
>> VDUS/N

i think you need to branket it as:

[VDUS/N]

in your sql statement... like:

strSQL = "UPDATE Computers " & _
  "SET ComputerType = '" & Replace(cboEComputerType.Text, "'", "''") & "' " & _
   ", Make = '" & Replace(cboEComputerMake.Text, "'", "''") & "' " & _
   ", Model = '" & Replace(cboEComputerModel.Text, "'", "''") & "' " & _
   ", HardDrive = '" & Replace(Val(txtEHDD.Text), "'", "''") & "' " & _
   ", RAM = '" & Replace(Val(txtERAM.Text), "'", "''") & "' " & _
   ", CDType = '" & Replace(cboECDType.Text, "'", "''") & "' " & _
   ", NetworkCard = '" & Replace(cboENIC.Text, "'", "''") & "' " & _
   ", MouseMake = '" & Replace(txtEMouseMake.Text, "'", "''") & "' " & _
   ", [MouseS/N] = '" & Replace(txtEMouseSerialNumber.Text, "'", "''") & "' " & _
   ", KeyboardMake = '" & Replace(txtEKboardMake.Text, "'", "''") & "' " & _
   ", [KeyboardS/N] = '" & Replace(txtEKboardSerialNumber.Text, "'", "''") & "' " & _
   ", VDUMake = '" & Replace(cboEVDUMake.Text, "'", "''") & "' " & _
   ", VDUModel = '" & Replace(txtEVDUModel.Text, "'", "''") & "' " & _
   ", [VDUS/N] = '" & Replace(txtEVDUSerialNumber.Text, "'", "''") & "' " & _
   ", PrinterMake = '" & Replace(cboEPrinterMake.Text, "'", "''") & "' " & _
   ", PrinterModel = '" & Replace(cboEPrinterModel.Text, "'", "''") & "' " & _
   ", [PrinterS/N] = '" & Replace(txtEPrinterSerialNumber.Text, "'", "''") & "' " & _
   ", ScannerMake = '" & Replace(cboEScannerMake.Text, "'", "''") & "' " & _
   ", ScannerModel = '" & Replace(txtEScannerModel.Text, "'", "''") & "' " & _
   ", [ScannerS/N] = '" & Replace(txtEScannerSerialNumber.Text, "'", "''") & "' " & _
   ", ModemMake = '" & Replace(cboEModemMake.Text, "'", "''") & "' " & _
   ", ModemModel = '" & Replace(txtEModemModel.Text, "'", "''") & "' " & _
   ", [ModemS/N] = '" & Replace(txtEModemSerialNumber.Text, "'", "''") & "' " & _
  "WHERE SerialNumber = '" & txtComputerSearchEdit & "'"
 rstConnGenericRecordset.Execute strSQL

and check as what emoreau mentioned above, cheers
Éric MoreauSenior .Net ConsultantCommented:
very nice catch ryancys !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.