Results 1 to 3 of 3

Thread: Problem with parameter query

  1. #1

    Thread Starter
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    Can anyone point me in the right direction with the the
    "parameter.value" property for queries. I believe this is causing my problem. When I run a query that expects numeric input it runs fine, If I run a similar query but this time expecting text input it returns all of the records from my table.

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    how are you using this parameter? is this an ADO parameter object? post some code please

  3. #3

    Thread Starter
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    I worked on it for a little while today & seem to have fixed it. Here's the code for the query, It is from a Laboratory Tracking program that I am working on. This part will search & return the results based on the chemical name.

    Sub cmdQueryChemical_Click()

    Dim cnnLabTracking As New Connection
    Dim rsChemicalName As Recordset
    Dim cmd1 As Command
    Dim prm1 As ADODB.Parameter
    Dim str1 As String
    Dim fldLoop As ADODB.Field
    Dim ChemName As String

    Set cmd1 = New ADODB.Command

    With cmd1
    .ActiveConnection = _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\My Documents\EXCEL FILES\Lab Tracking.mdb;"
    .CommandText = "PARAMETERS [ChemicalName] String;" & _
    "SELECT SampleNumber, Chemical Name, Container Number, Container Weight, Description, Part Number, Batch, Operator, Screener, Department, Date " & _
    "FROM SampleLogin " & _
    "WHERE `Chemical Name` Like [ChemicalName]"
    .CommandType = adCmdText
    End With

    'Create and Define new parameter

    Set prm1 = cmd1.CreateParameter("[ChemicalName]")

    ChemName = Trim(InputBox("Enter Chemical Name"))
    prm1.Type = adVarWChar
    prm1.Size = 255
    prm1.Direction = adParamInput
    prm1.Value = ChemName
    cmd1.Parameters.Append prm1

    'Run parameter query.
    cmd1.Execute

    'Clear data grid.
    vfgSearchResults.Clear

    'Open recordset on cmd1
    Set rsChemicalName = New ADODB.Recordset
    rsChemicalName.Open cmd1

    Do Until rsChemicalName.EOF
    vfgSearchResults.AddItem str1, 1
    str1 = ""
    For Each fldLoop In rsChemicalName.Fields
    str1 = str1 & fldLoop.Value & Chr(9)
    Next fldLoop
    vfgSearchResults.Refresh
    ' Debug.Print str1
    rsChemicalName.MoveNext
    Loop

    rsChemicalName.Close

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width