Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1512

Retrieve specified data from access to excel

$
0
0
Hi,

I'm trying to catch one row from an access database in a recordset butt I'm stuck on the SQL part in the code.
I constantly get a syntax error on the FROM component. SQL statement works fine in access.
Does someone has any idee what's wrong with my code?


Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim MyConn

Set cn = New ADODB.Connection
MyConn = "N:\Beeuwsaert-Construct\Klanten\Dossiernummers Beewsaert Construct1.mdb"

With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open MyConn
End With

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer

strSQL = "SELECT Werfadres, Werfpostcode, Werfplaats, Land FROM Klanten WHERE Nummer = " & werfnr
rs.Open Source:=strSQL, ActiveConnection:=cn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable
Attached Images
 

Viewing all articles
Browse latest Browse all 1512

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>