PDA

Click to See Complete Forum and Search --> : UPDATE and INSERT SQL questions


cedx
Nov 23rd, 2000, 09:34 PM
Hi,

How do I use UPDATE and INSERT type SQL statements in a database and recordset declared in code?

I use the following for SELECT statements:


SQL = "SELECT * FROM Employees"
Set db = OpenRecordset(dbPath)
Set rs = db.OpenRecordset(SQL)


I can't seems to get rs.Execute(SQL) to work. What am I doing wrong?

Thanks in advance.

Nina
Nov 24th, 2000, 04:03 AM
StrSQL = "INSERT INTO " & Table_Name & _
" (" & StrFields & ") " & _
" VALUES (" & StrValues & ")"
'Debug.Print StrSQL

Dim cmd as ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = cnDB
cmd.CommandText = StrSQL
cmd.Execute
Set cmd = Nothing

cedx
Nov 24th, 2000, 07:44 PM
Thanks Nina.

honeybee
Nov 24th, 2000, 11:04 PM
I do it in DAO as this:


SQL = "Update ......"
dbMaster.Execute SQL


If you are not getting this right, maybe you are using parenthesis around the query, like:


SQL = "Update ...."
dbMaster.Execute(SQL)


Try omitting the parenthesis and it should work.