?
Solved

SQL as recordset in VB

Posted on 1998-09-15
8
Medium Priority
?
439 Views
Last Modified: 2012-08-14
I am using a SQL to query and Access DB.  I want this data to be the chart Data for MSCHART.  What is wrong with this?

Dim WS As DAO.Workspace
Dim DB As DAO.Database
 ' Initialize a default workspace
Set WS = CreateWorkspace("TestWS", "Admin", "", dbUseJet)
Set DB = WS.OpenDatabase("c:\windows\desktop\wkformula.mdb")
Set wb = DB.OpenRecordset("CMLtable")
With wb
Dim ol As Recordset
Dim STRSQL
STRSQL = "SELECT OSBAL FROM CMLTABLE WHERE YEAR='1998'"
Set ol = DB.OpenRecordset(STRSQL)
Me!MSChart1.ChartData = ol

Thanks
0
Comment
Question by:dhill10358
[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
8 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1434985
Does your field YEAR a string or date field?
0
 
LVL 18

Expert Comment

by:deighton
ID: 1434986
What is the error message you are getting?
0
 

Author Comment

by:dhill10358
ID: 1434987
Hi,

It gives me a runtime error.

The Year is actually in the Access table, but it is a text field. I know the sql statement is ok, but I get "Bad Function Argument"  Runtime error 1101.

Any Suggestions?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:cymbolic
ID: 1434988
I've commented out what I don't think you need, and modified it to what should work:

'Set wb = DB.OpenRecordset("CMLtable")
'With wb
Dim ol As Recordset
Dim STRSQL
STRSQL = "SELECT OSBAL FROM CMLTABLE WHERE YEAR='1998'"
Set ol = DB.OpenRecordset(STRSQL)
if not ol.eof then
 Me!MSChart1.ChartData = ol(0) 'or ol("OSBAL") or ol!OSBAL
endif
ol.close
etc...
0
 

Author Comment

by:dhill10358
ID: 1434989
Thanks for you help, but I get the exact same error message, the only difference is when I try to debug, the OL(0) or ol("osbal") has a value now.  But it has the same error msg.

Thanks
0
 

Expert Comment

by:balrogzed
ID: 1434990
I think you may need to change your sql statement to use double quotes not single quotes. ie change
STRSQL = "SELECT OSBAL FROM CMLTABLE WHERE YEAR='1998'"
to
STRSQL = "SELECT OSBAL FROM CMLTABLE WHERE YEAR=""1998"""
0
 

Author Comment

by:dhill10358
ID: 1434991
Thanks, but that is not the problem.  When I am debugging I can see the results of the SQL. I use the exact same statement in to append a recordset to excel, and it works.

Thanks
0
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 160 total points
ID: 1434992
IS that a forward only Recordset?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

777 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