Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Advice: Exporting Query Results (VB/SQL)

Posted on 2001-06-14
4
Medium Priority
?
171 Views
Last Modified: 2012-05-04
I have a reporting tool that was created for users to generate criteria (sql statement).  For one reporting option the user needs to export the results of the sql statement they create(graphically) to be exported to a .txt file in a certain format - ; seperated.

Right now I am using a word merge and saving it as .txt...works fine...but its a little slower than I would like and there should be a more efficient way.

Can I do this at the SQL end....BCP? etc...
I have the sql string in a variable so I can use it however I want...

What would you do??
0
Comment
Question by:setfocus
  • 2
4 Comments
 
LVL 2

Expert Comment

by:chandukb
ID: 6192057
Try Recordset's SAVE method, see msdn for syntax.

Chandu
0
 

Author Comment

by:setfocus
ID: 6192105
can I use semi colon delimitted fields??  I need this to be the case.

if it was that simple...it would be great!
0
 
LVL 2

Expert Comment

by:chandukb
ID: 6192210
0
 
LVL 6

Accepted Solution

by:
andyclap earned 240 total points
ID: 6194683
Unfortunately the .save method only supports XML and a MS propriety format.
However, with a bit of simple code, you can very quickly save the recordset to a text file.

Chandu's link is good, although it's not the most efficient way of doing it (doing a field.value on each element can be a little slow). There's probably even more efficient ways too, but heres my 2c worth.

Note this sample uses implicit string conversion for the recordset's contents - it is probably a good idea to explicitly conver each element depending on the vartype so that you know the output formats.

Private Sub SaveRS(ByVal rs As Recordset, ByVal sFile As String)

    'save the recordset to the file semicolon delimited
    Dim vaRows As Variant
    Dim lRow As Long
    Dim lCol As Long
    Dim iFile As Integer
   
    vaRows = rs.GetRows()
   
    iFile = FreeFile
    Open sFile For Output As iFile
   
    For lRow = LBound(vaRows, 2) To UBound(vaRows, 2)
        For lCol = LBound(vaRows, 1) To UBound(vaRows, 1)
            If lCol <> 0 Then
                Print #iFile, ";";
            End If
            'this will implicitly convert to a string
            'so it might be best to write some explicit conversion code here
            Print #iFile, vaRows(lCol, lRow);
        Next
        If lRow <> UBound(vaRows, 2) Then
            Print #iFile,
        End If
    Next
    Close iFile
           
   
End Sub

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

916 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