Passing Parameter in Select Statement 
Author Message
 Passing Parameter in Select Statement

Hope someone can help as it seems the books I have all skirt around this.
Anyway, I am trying to pass the criteria back to an coded select statement
and it doesn't bring back any results. If I hard code the WHERE criteria, it
works and retrieves the results. This is not very convenient as you might
imagine.

I created an InputBox to have the User enter the criteria and attempted to
pass this back through a variable. I have checked to ensure the value is
stored by passing it back to a label. This is working ok.

Anyway, here is the code for that event. If anyone can tell me where I am
going wrong, please let me know.

Thanks in advance,

Private Sub cmdSelect_Click()
    Dim Message, Title, Default, strSelect
    Message = "Enter a Part Number"   ' Set prompt.
    Title = "Part Number" ' Set title.
    Default = "*"   ' Set default.

    strSelect = "PARAMETERS [PartNum]"
    strSelect = Trim(InputBox(Message, Title, Default))
    lblPart.Caption = strSelect
    datData.RecordSource = "Select * FROM Parts WHERE PartNum Like
'strSelect' ;"
    datData.Refresh
End Sub



Wed, 06 Dec 2000 03:00:00 GMT  
 Passing Parameter in Select Statement

Change your select statement to:

    datData.RecordSource = "Select * FROM Parts WHERE PartNum Like '" & _
        strSelect & "'"

The reason your statement is returning nothing is that it's searching for a
part number equal to the string "strSelect".

Lee Weiner
weiner AT fuse DOT net


Quote:

>Hope someone can help as it seems the books I have all skirt around this.
>Anyway, I am trying to pass the criteria back to an coded select statement
>and it doesn't bring back any results. If I hard code the WHERE criteria, it
>works and retrieves the results. This is not very convenient as you might
>imagine.

>I created an InputBox to have the User enter the criteria and attempted to
>pass this back through a variable. I have checked to ensure the value is
>stored by passing it back to a label. This is working ok.

>Anyway, here is the code for that event. If anyone can tell me where I am
>going wrong, please let me know.

>Thanks in advance,

>Private Sub cmdSelect_Click()
>    Dim Message, Title, Default, strSelect
>    Message = "Enter a Part Number"   ' Set prompt.
>    Title = "Part Number" ' Set title.
>    Default = "*"   ' Set default.

>    strSelect = "PARAMETERS [PartNum]"
>    strSelect = Trim(InputBox(Message, Title, Default))
>    lblPart.Caption = strSelect
>    datData.RecordSource = "Select * FROM Parts WHERE PartNum Like
>'strSelect' ;"
>    datData.Refresh
>End Sub



Thu, 07 Dec 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. select statement and parameters

2. Multi-parameter SELECT statements?

3. VB6 - Problem passing multiple parameters to Command SQL statement

4. Shell statement - passing a parameter.

5. Passing parameters to IF-Statement SP

6. Passing Parameters to IF-Statement SP

7. Problem Passing parameters to select query

8. How to select the current record only with SELECT statement

9. passing parameter to a parameter query

10. Passing Parameters to stored parameter queries using VB 5's Data Controls

11. passing optional parameters to the parameters collection

12. Max Number of Parameters In Parameter Passing

 

 
Powered by phpBB® Forum Software