Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default ADODB SQL help

Can anyone here tell me what is wrong with my SQL statement? I get a error of
Expected 1.

Sub UpdateData2()
On Error GoTo ErrorHandler

Dim MyCn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String

Set MyCn = New ADODB.Connection

' Replace actual Access file path here
MyCn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" _
& "DBQ=G:\TestCQA.mdb"

Set rst = New ADODB.Recordset

strSQL = "SELECT * FROM tblExcel" _
& " WHERE tblExcel.TestID = " & Range("A2").Value

rst.Open strSQL, MyCn

If rst!IsReviewed = False Then 'no edit statement here?
rst!IsReviewed = True
rst.Update
End If

MyCn.Close

ErrorHandler_Exit:
Set MyCn = Nothing
Exit Sub

ErrorHandler:
MsgBox Err.Description
GoTo ErrorHandler_Exit

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default ADODB SQL help

You may need to put single quotes around the Range.Value if its text
ie,
" WHERE tblExcel.TestID = '" & Range("A2").Value & "'"

either that or tblExcel.TestID doesn't exist

Eric wrote:
Can anyone here tell me what is wrong with my SQL statement? I get a error of
Expected 1.

Sub UpdateData2()
On Error GoTo ErrorHandler

Dim MyCn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String

Set MyCn = New ADODB.Connection

' Replace actual Access file path here
MyCn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" _
& "DBQ=G:\TestCQA.mdb"

Set rst = New ADODB.Recordset

strSQL = "SELECT * FROM tblExcel" _
& " WHERE tblExcel.TestID = " & Range("A2").Value

rst.Open strSQL, MyCn

If rst!IsReviewed = False Then 'no edit statement here?
rst!IsReviewed = True
rst.Update
End If

MyCn.Close

ErrorHandler_Exit:
Set MyCn = Nothing
Exit Sub

ErrorHandler:
MsgBox Err.Description
GoTo ErrorHandler_Exit

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB Connection fi.or.jp.de Excel Worksheet Functions 0 September 9th 09 09:23 PM
ADODB Question luvgreen Excel Programming 8 November 15th 04 11:46 AM
Problems with ADODB Eric Wescott Excel Programming 6 October 20th 04 03:50 PM
ADODB Richard Mogy Excel Programming 3 May 6th 04 09:14 PM
ADODB Recordset Seth[_3_] Excel Programming 0 August 5th 03 02:15 PM


All times are GMT +1. The time now is 04:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"