[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL as recordset in VB

Posted on 1998-09-15
8
Medium Priority
?
449 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

656 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