Solved

Sql Statement Problem in VB6

Posted on 2001-07-30
2
192 Views
Last Modified: 2012-06-27
I am having trouble with a SQL Statement.

I can get it to work with fields that have numeric values, but when I set up the fields that I need that contain text values, I get the following error:

"No Value given for one or more required parameter"

I hope I am just overlooking something small and quick to fix...

If you need more info just ask...

Thanks

Here is my code:

**** Code that causes error ******
**** Code that I need to work with text data ******

Function MyGetTestPhase()

Dim cnn As adodb.Connection
Dim rst As adodb.Recordset
Set cnn = New adodb.Connection
Set rst = New adodb.Recordset
Dim cmd As New adodb.Command
Dim objrs As adodb.Recordset
Dim strsql As String

dbSrc = "h:\Access\NT\NT_Cat_dbs.mdb"

cnn.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & dbSrc

Set cmd.ActiveConnection = cnn

rst.Open "[Test Animals]", cnn

*****Database Field that is Text*******
NTValue = "NT945"
***************************************

strsql = "Select [Test Animals].[Test Number] " & _
         "From [Test Animals], [Test Information] " & _
         "Where [Test Information].NT = " & NTValue

Set objrs = cnn.Execute(strsql)

test = objrs![Test Number]

End Function




*******  Code that works ****
*******  Code that contains Numeric data ******

Function MyGetTestPhase()

Dim cnn As adodb.Connection
Dim rst As adodb.Recordset
Set cnn = New adodb.Connection
Set rst = New adodb.Recordset
Dim cmd As New adodb.Command
Dim objrs As adodb.Recordset
Dim strsql As String

dbSrc = "h:\Access\NT\NT_Cat_dbs.mdb"

cnn.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & dbSrc

Set cmd.ActiveConnection = cnn

rst.Open "[Test Animals]", cnn

*****Database field that is numeric******
PhaseValue = 10
*****************************************
strsq2 = "Select [Test Animals].[Test Number] " & _
         "From [Test Animals], [Test Information] " & _
         "Where [Test Information].Phases = " & PhaseValue

Set objrs = cnn.Execute(strsq2)

test2 = objrs![Test Number]

End Function
0
Comment
Question by:ataripirate
2 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
Comment Utility
text fields require that the parameters be enclosed in single quotes, e.g.,

strsql = "Select [Test Animals].[Test Number] " & _
        "From [Test Animals], [Test Information] " & _
        "Where [Test Information].NT = '" & NTValue & "'"
0
 
LVL 3

Expert Comment

by:casassus
Comment Utility
use

strsql = "Select [Test Animals].[Test Number] " & _
        "From [Test Animals], [Test Information] " & _
        "Where [Test Information].NT = '" & NTValue & "'"

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now