Solved

Help with Syntax

Posted on 2006-07-11
1
169 Views
Last Modified: 2010-04-30
This Excel VBA

I have this piece of code that works with this statement in it
Recordset.Open "Select * from [Data]", db, adOpenStatic, adLockOptimistic
but if I had the where statement, it doesn't

 Recordset.Open "Select * from [Data] where [data]![CompanyId] = TradeLimit.ComboBox1.Value", db, adOpenStatic, adLockOptimistic

What is the right syntax?


Any help would greatly be appreciated!!
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' ////Load Data
 Set Recordset = New ADODB.Recordset
    db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=C:\Documents and Settings\n574824\Databases\SRP\SRPtwo.mdb;"
   
 Recordset.Open "Select * from [Data] where [data]![CompanyId] = TradeLimit.ComboBox1.Value", db, adOpenStatic, adLockOptimistic

    i = 25
  With Recordset
''''''''''''''''''''''''''''''''''''''''''
'Add Recordset

    Cells(25, 4).CopyFromRecordset Recordset
'/////////////////////////////
0
Comment
Question by:ca1358
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17085627
   
assuming the CompanyID is numeric:

 Recordset.Open "Select * from [Data] where [data]![CompanyId] = " & TradeLimit.ComboBox1.Value , db, adOpenStatic, adLockOptimistic
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 59
RUNRMTCMD from AS/400 12 44
VB6 - Scroll Mouse wheel on Picturebox 13 42
Copy a range from 1..n excel sheets to one destination sheet 2 30
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question