Dr_Evil
Mar 27th, 2000, 07:49 PM
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.
Clunietp
Mar 27th, 2000, 10:38 PM
how are you using this parameter? is this an ADO parameter object? post some code please
Dr_Evil
Mar 28th, 2000, 01:11 AM
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