Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cell value as parameter for VBA access query


It's the where clause in the SQL statement.
Use...

(If CONTR_NBR is a number) Where CONTR_NBR=" & contract
(If CONTR_NBR is text) Where CONTR_NBR='" & contract &"'"

So it should be...

Sub squery()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cstring As String
Dim qstr, contract As String
Dim intRow As Integer
Dim DBasePath As String
Dim I

cstring = "C:\CovB.mdb"

Set cn = New ADODB.Connection
With cn
..Provider = "Microsoft.JET.OLEDB.4.0"
..Open cstring
End With

Set rs = New ADODB.Recordset
rs.ActiveConnection = cn

For I = 1 To 10

contract = Sheets(1).Range("A" & I)
qstr = "Select CONTR_NBR, COV_TYPE, BENEFIT From CB Where CONTR_NBR=" &
contract
rs.Open qstr, cn

Do Until rs.EOF
intRow = intRow + 1
Sheets(2).Cells(intRow, 1) = rs.Fields("CONTR_NBR")
Sheets(2).Cells(intRow, 2) = rs.Fields("COV_TYPE")
Sheets(2).Cells(intRow, 3) = rs.Fields("BENEFIT")
rs.MoveNext
Loop

rs.Close

Next
ThisWorkbook.Save

cn.Close

End Sub


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=486866

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
pass parameter to access query Bill Manville Links and Linking in Excel 4 May 1st 23 03:45 AM
Pivot Table From Access Parameter Query Paul Smith[_4_] Excel Programming 1 January 13th 05 04:04 PM
Use ADO to retrieve data from Access Parameter Query CodeMonkey Excel Programming 3 December 17th 04 08:45 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM
Pass Parameter to Access Query Al Excel Programming 3 April 29th 04 10:15 AM


All times are GMT +1. The time now is 02:18 PM.

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"