SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Dec 2007
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Retreive Data And store in Excel

    Hi Everyone,

    After searching the forum i found some code where i can connect to Database and retrieve data.I want to export the data into Excel.can anyone plz provide me some sample code for this.I saw posts where people talking about recordset,
    can anyone tell what it is and how it is useful.
    The code which i used is as follows:
    Dim rs,sq,pkey
    set conn=createobject("adodb.connection")
    set rs=createobject("adodb.recordset")
    conn.open= "Provider=Microsoft.Jet.OLEDB.4.0;_
    DataSource=C:\Documents and Settings\218820_ \Desktop\Test1.mdb;User ID=Admin"
    sql="Select * from Books"
    rs.open sql,conn

    rs.close
    set rs=nothing

    conn.close
    set conn=nothing

    Thanks And Regards,
    shiva :

  2. #2
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Retreive Data And store in Excel

    Shiva use this to return a record set and loop thru it, see my comment where to add the write to Excel, there is lots of examples of this if you search.

    '================================================= ==============================
    ' Execute the string
    Set rs = Connect.Execute (sql,,adcmdtext)
    ' Check if zero records returned
    If rs.EOF and rs.BOF Then
    ' Put if no recs returned processing here
    MsgBox " No records returned from Database"
    Else
    ' Records returned, move to 1st record
    rs.MoveFirst
    ' loop thru all records returned
    do while not rs.EOF
    ' Process returned records here

    '### Add Code Here to write record to Excel ####

    ' Read next record
    rs.MoveNext
    ' Do until EOF
    loop
    end if
    '================================================= ==============================

    Mark Smith.

  3. #3
    Junior Member
    Join Date
    Dec 2007
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Retreive Data And store in Excel

    Thanks mark, I will try this and revert back incase if i face any problem.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 12.50%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 03:57 AM.

Copyright BetaSoft Inc.