Solved

Sql Statement Problem in VB6

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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