Solved

Sql Statement Problem in VB6

Posted on 2001-07-30
2
212 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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