Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to fetch no.of data from sql using Macro(VB)

how to fetch no.of data from sql using Macro(VB)

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tech_spidy
    wrote on last edited by
    #1

    Hi all, I can able to fetch a single data from Sql and display it in the Excel sheet using Macro, this is the code. I am getting in the Text Box: sno = TextBox1.Text When i am clicking the Ok button: Query = "Select sname,scity from smaster where snum='" & sno & "'" Set QueryRs = oConn.Execute(Query) Sheet1.Cells(1, 1) = QueryRs("sname") Sheet.Cells(1, 2) = QueryRs("scity") Result: Name, city displayed in the Excel sheet1 Now my problem is how to fetch multiple data and display (like how to use loop in it) waiting for timely help

    Tech_spidy

    T 1 Reply Last reply
    0
    • T Tech_spidy

      Hi all, I can able to fetch a single data from Sql and display it in the Excel sheet using Macro, this is the code. I am getting in the Text Box: sno = TextBox1.Text When i am clicking the Ok button: Query = "Select sname,scity from smaster where snum='" & sno & "'" Set QueryRs = oConn.Execute(Query) Sheet1.Cells(1, 1) = QueryRs("sname") Sheet.Cells(1, 2) = QueryRs("scity") Result: Name, city displayed in the Excel sheet1 Now my problem is how to fetch multiple data and display (like how to use loop in it) waiting for timely help

      Tech_spidy

      T Offline
      T Offline
      Tom Deketelaere
      wrote on last edited by
      #2

      dim rst as dao.recordset dim query as string query = "select sname,scity from smaster" set rst = oconn.execute(query) dim i as integer i = 1 do while not rst.eof Sheet1.Cells(i, 2) = QueryRs("sname") Sheet.Cells(i, 1) = QueryRs("scity") i +=1 loop I think this will work (haven't tested it dough)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups