Solved

SQL as recordset in VB

Posted on 1998-09-15
8
434 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 80 total points
ID: 1434992
IS that a forward only Recordset?
0

Featured Post

Industry Leaders: 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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

728 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