Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sql Statement Problem in VB6

Posted on 2001-07-30
2
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 6334984
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
ID: 6334988
use

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

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses

721 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