Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 20th, 2003, 05:55 PM
tarlejh tarlejh is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 tarlejh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to tarlejh Send a message via Yahoo to tarlejh
using an SQL query as RecordSource

I'm working on a database application in Visual Basic 6. The database seems to connect fine. Now I'm merely trying set RecordSource properties to an SQL query in run-time instead of a table, but when I run it it crashes. It seems like it will only let me use tables. Something to this effect is what I get when I hit run:


quote:
--------------------------------------------------------------------------------

"Error 3011 Jet Engine cannot find Object "SELECT ClientMap.ClientName, ClientMap.Consultant_LName FROM ClientMap"
--------------------------------------------------------------------------------

and then it points to debug at datData1.Refresh.

What am I doing wrong?
Comments on this post
Gran Roguismo agrees!

Reply With Quote
  #2  
Old May 20th, 2003, 10:45 PM
wbeetge wbeetge is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 7 wbeetge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 22 sec
Reputation Power: 0
You are using a datacontrol for you datasrouce.

There should be a property (in the connection) that you can set, or in the dataControl itself where you tell it what kind of datasource to use in the query.

Graham
Comments on this post
Gran Roguismo agrees!

Reply With Quote
  #3  
Old May 21st, 2003, 07:50 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,827 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 22 h 57 m 29 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
I will give you an example of how I do this.
This is done with ADO.
First, I have this function which returns a recordset (readonly)
Code:
'opens an ado read only recordset
Public Function OpenRSro(sql As String) As ADODB.Recordset
    Dim rst As ADODB.Recordset
    Set rst = New ADODB.Recordset
    rst.Open sql, cn, adOpenForwardOnly
    Set OpenRSro = rst
End Function

Now, lets say I have a DataGrid control on my form and a text box and a command button. When the user clicks the command button, it executes the sql statement entered into the text box.
So I would have some code like this:
Code:
Private Sub Command1_Click()
    Set DataGrid1.DataSource = OperRSro(Text1.Text)
End Sub

This is just a simplified version, but you get the idea. You have to set the datasource property = to the recordset returned, and it does have to be done with set.

Reply With Quote
  #4  
Old May 21st, 2003, 08:39 AM
wbeetge wbeetge is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 7 wbeetge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 22 sec
Reputation Power: 0
Seems OK.

Does the first query into the recordset execute correctly ?

Can you look at the data in the recordset before you assign it to the grid?

Have you tried setting the command type in your connection ?
Add this to your code in the connection bit and replace the ? with the type of command youe would like it to be


Dim a As ADODB.Command

Set a = New ADODB.Command
a.CommandText = ?

The last to lines must be done before the Open command

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > using an SQL query as RecordSource


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway