Running a SQL command

B

Bre-x

Hi,
I need to update a record on a ms access database from MS Excel (Office
2000)
I dont need nor i want to open the ms acesss db

This is the sql command

"UPDATE DB_ToolSheet SET DB_ToolSheet.HasChanged = 'Yes' WHERE
[DB_ToolSheet].[ToolSheetID]=" & Sheets("Data").Range("A1").Value;"

I hope someone can help me with this function I am new using MS Excel

Thank you all,

Bre-x
 
B

Bre-x

Sub InsertData()
Dim cnn As Connection
Dim ConStr As String, Sql As String
ConStr = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=E:\Access\CNC\CNC_Tables.mdb;" & _
"Uid=admin;" & _
"Pwd="
Sql = "UPDATE DB_ToolSheet SET DB_ToolSheet.HasChanged = 'Yes' WHERE
[DB_ToolSheet].[ToolSheetID]= " & Sheets("Data").Range("A3").Value
Set cnn = New ADODB.Connection
With cnn
.Open ConStr
.Execute (Sql)
.Close
End With
Set cnn = Nothing
End Sub
 
B

Bre-x

Actually some how this command is corrupting the all record.
please do not use.

Bre-x
 
F

Francine Kubaka

Bre-X, right?

Anyway, you may want to check the variable types - the ones you writing
back to the database.

Like this:
Dim vToolSheetID as Variant
Dim strSQL as String
vToolSheetID = Sheets("Data").Range("A3").Value
strSQL = "UPDATE DB_ToolSheet SET HasChanged = 'Yes' WHERE
ToolSheetID= " & CLng(vToolSheetID) &";"
........
Secondly, you may want to do it with DAO. DAO works much smoother with
Excel.

Thirdly, try and retrieve the records you need first and check if your SQL
statement retrieves them correctly.

Cheers,
A


Bre-x said:
Actually some how this command is corrupting the all record.
please do not use.

Bre-x


Bre-x said:
Sub InsertData()
Dim cnn As Connection
Dim ConStr As String, Sql As String
ConStr = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=E:\Access\CNC\CNC_Tables.mdb;" & _
"Uid=admin;" & _
"Pwd="
Sql = "UPDATE DB_ToolSheet SET DB_ToolSheet.HasChanged = 'Yes' WHERE
[DB_ToolSheet].[ToolSheetID]= " & Sheets("Data").Range("A3").Value
Set cnn = New ADODB.Connection
With cnn
.Open ConStr
.Execute (Sql)
.Close
End With
Set cnn = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top