Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Select with VB6

Posted on 2011-03-06
2
Medium Priority
?
793 Views
Last Modified: 2012-05-11
I know this has been answered many times but can't find the exact answer I am looking forward.  I am connecting to a database from which I want to lean how to use SQL statements in VB6.  I want to be able to select records and then output them in a text file (or screen if desired).  Once I execute the SQL SELECT * FROM database name WHERE ... how do I get just those records to the text file or screen and not the whole database.  Can someone give me some sample code?
0
Comment
Question by:grandrew
[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
 

Author Comment

by:grandrew
ID: 35047607
While that is a nice site, it does not show me how to integrate with VB6.
0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 2000 total points
ID: 35056101
Q1.  How to get just those records ... and not the whole database..
   A1.  Seems like your example should be SQL = "Select Fields from Table where condition"
   Example:
  DIM SQL AS STRING
  Dim RS as new adodb.recordset
  Dim CN as new adodb.connection

  cn.open "connection to your database"
  SQL = "SELECT ADDRESS, NAME FROM CUSTOMERS WHERE STATE = 'Texas' "
  rs.open SQL,CN, adOpenStatic, adLockBatchOptimistic
  DO WHILE NOT RS.EOF
  ' OUTPUT AS DESIRED....
   RS.MOVENEXT
  LOOP

Q2.  output them in a text file (or screen if desired)
   A2.  So you want an example of text file out put?
    Example:
    Dim sFile as string
    Dim SQL AS STRING
    Dim RS as new adodb.recordset
    Dim CN as new adodb.connection

    sFile = app.path & "\OutPut.txt"
    open sFile for output as #1

  cn.open "connection to your database"
  SQL = "SELECT ADDRESS, NAME FROM CUSTOMERS WHERE STATE = 'Texas' "
  rs.open SQL,CN, adOpenStatic, adLockBatchOptimistic
  DO WHILE NOT RS.EOF
       Print #1, RS!NAME & ", " & RS!ADDRESS
      RS.MOVENEXT
  LOOP
 Close #1
   
 If you wish this to out put to the screen then you need a grid control or other ActiveX object..
   then bind your RS to that object...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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

715 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