how to fetch no.of data from sql using Macro(VB)
-
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
-
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
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)