Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Can someone tell me what i am doeing wrong?

I use the following code.

Sub ADOImportFromAccessTable(DBFullName As String, TableName As String, TargetRange As Range)
' Example: ADOImportFromAccessTable "C:\FolderName\DataBaseName.mdb", _
"TableName", Range("C1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set TargetRange = TargetRange.Cells(1, 1)
target = TargetRange.Cells(1, 1)
' open the database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DBFullName & ";"
Set rs = New ADODB.Recordset
With rs
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = " & TargetRange, cn, , , adCmdText
waarde = rs.Fields(intColIndex).Value
TargetRange.Offset(0, 1) = waarde

I get the error
syntaxerror operator missing.

Can someone help
Thanks Hans
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Can someone tell me what i am doeing wrong?

Hans,

If PostCode is a text field you need to enclose the referenced text in double or single quotes. Singles are the simpler:

.Open "SELECT * FROM Postcode WHERE [Postcode] = '" & TargetRange.Value & "'", cn, , , adCmdText

Copy the above line to your code module and the sequence of quotes will be much easier to read.

--

John Green - Excel MVP
Sydney
Australia


"hans" wrote in message ...
I use the following code.

Sub ADOImportFromAccessTable(DBFullName As String, TableName As String, TargetRange As Range)
' Example: ADOImportFromAccessTable "C:\FolderName\DataBaseName.mdb", _
"TableName", Range("C1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set TargetRange = TargetRange.Cells(1, 1)
target = TargetRange.Cells(1, 1)
' open the database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DBFullName & ";"
Set rs = New ADODB.Recordset
With rs
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = " & TargetRange, cn, , , adCmdText
waarde = rs.Fields(intColIndex).Value
TargetRange.Offset(0, 1) = waarde

I get the error
syntaxerror operator missing.

Can someone help
Thanks Hans

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Can someone tell me what i am doeing wrong?

solved it
"hans" schreef in bericht ...
I use the following code.

Sub ADOImportFromAccessTable(DBFullName As String, TableName As String, TargetRange As Range)
' Example: ADOImportFromAccessTable "C:\FolderName\DataBaseName.mdb", _
"TableName", Range("C1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set TargetRange = TargetRange.Cells(1, 1)
target = TargetRange.Cells(1, 1)
' open the database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DBFullName & ";"
Set rs = New ADODB.Recordset
With rs
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = " & TargetRange, cn, , , adCmdText
waarde = rs.Fields(intColIndex).Value
TargetRange.Offset(0, 1) = waarde

I get the error
syntaxerror operator missing.

Can someone help
Thanks Hans
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
What's wrong in this Eqn? Raz Excel Worksheet Functions 1 January 12th 10 07:27 PM
what is the wrong? rajaiy Excel Worksheet Functions 0 July 27th 09 11:45 AM
What is wrong? robert morris Excel Discussion (Misc queries) 5 February 6th 09 02:37 AM
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
What am I doing wrong? Jeff New Users to Excel 4 March 6th 05 03:05 AM


All times are GMT +1. The time now is 07:11 AM.

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

About Us

"It's about Microsoft Excel"