Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Explicitly passing a .value

Hi,

I'm trying to filter by making an SQL statement which ties in the value
of a cell. The cell in question is B15. In my particular test case, it
has a value of 111-K. However, it will normally be a dynamic value in
the same format.

If I refer to it like I do in my code below, I receive the error
"incorrect syntax near 'K' "

If I change the query and say "AND MAIN.PART_NO = '111-K' " it works
fine, because its tied together with the quotes.

Any thoughts as to how I can get this working based on a cell value?

The code is below




strQuery3 = "SELECT PARTS.TYPE " & _
"FROM MAIN, PARTS " & _
"WHERE MAIN.ID=INDUCTORS.PART_ID " & _
"AND MAIN.PART_NO =" & Range("B15").Value
With rs3
.Open strQuery3, dbConn2, adOpenStatic
noRecords = .RecordCount
Range("D15").CopyFromRecordset rs3
.Close
End With

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Explicitly passing a .value

Try wrapping the value of B15 in single quotes:

"AND MAIN.PART_NO ='" & Range("B15").Value & "'"


mazzarin wrote:
Hi,

I'm trying to filter by making an SQL statement which ties in the value
of a cell. The cell in question is B15. In my particular test case, it
has a value of 111-K. However, it will normally be a dynamic value in
the same format.

If I refer to it like I do in my code below, I receive the error
"incorrect syntax near 'K' "

If I change the query and say "AND MAIN.PART_NO = '111-K' " it works
fine, because its tied together with the quotes.

Any thoughts as to how I can get this working based on a cell value?

The code is below




strQuery3 = "SELECT PARTS.TYPE " & _
"FROM MAIN, PARTS " & _
"WHERE MAIN.ID=INDUCTORS.PART_ID " & _
"AND MAIN.PART_NO =" & Range("B15").Value
With rs3
.Open strQuery3, dbConn2, adOpenStatic
noRecords = .RecordCount
Range("D15").CopyFromRecordset rs3
.Close
End With

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Explicitly passing a .value

Bingo!

Figured I had to manipulate the single quotes some special way,
couldn't figure out how.

Thanks again.


Bill Schanks wrote:
Try wrapping the value of B15 in single quotes:

"AND MAIN.PART_NO ='" & Range("B15").Value & "'"


mazzarin wrote:
Hi,

I'm trying to filter by making an SQL statement which ties in the value
of a cell. The cell in question is B15. In my particular test case, it
has a value of 111-K. However, it will normally be a dynamic value in
the same format.

If I refer to it like I do in my code below, I receive the error
"incorrect syntax near 'K' "

If I change the query and say "AND MAIN.PART_NO = '111-K' " it works
fine, because its tied together with the quotes.

Any thoughts as to how I can get this working based on a cell value?

The code is below




strQuery3 = "SELECT PARTS.TYPE " & _
"FROM MAIN, PARTS " & _
"WHERE MAIN.ID=INDUCTORS.PART_ID " & _
"AND MAIN.PART_NO =" & Range("B15").Value
With rs3
.Open strQuery3, dbConn2, adOpenStatic
noRecords = .RecordCount
Range("D15").CopyFromRecordset rs3
.Close
End With

Thanks!


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
Importing libraries explicitly in macro code shivboy[_7_] Excel Programming 3 June 14th 06 01:17 PM
How to explicitly set the regional code of an individual spreadsheet Scott Steiner Excel Discussion (Misc queries) 1 November 21st 05 02:34 PM
Solver with values not stored explicitly in cells Stacy35216[_9_] Excel Programming 1 November 18th 05 12:49 AM
Passing a Range Jerry Excel Programming 4 February 14th 05 10:52 AM
passing defined name to vb bmeehan[_2_] Excel Programming 1 May 25th 04 06:07 PM


All times are GMT +1. The time now is 03:14 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"