ado - Execution of a stored procedure with an input parameter and insert into specific cells in excel -
i have following vba routine
private sub cmdstartdate_click() 'set variables dim conn adodb.connection dim str string dim exestr string dim rs adodb.recordset dim fld dim integer dim connstr string dim cmd new adodb.command 'error handler on error goto errlbl 'open database connection set conn = new adodb.connection 'construct connection string conn = "driver={sql server};server=10.50.50.140;database=tbjc;uid=oe;pwd=orth03c0" 'open connection conn.open 'create command object set cmd = new adodb.command 'create , store start date parameter cmd .commandtext = "dbo.cusultrasoundreport" .commandtype = adcmdstoredproc .parameters.append .createparameter("@start", advarchar, adparaminput, 12, txtstartdate.text) .parameters("@start").value = txtstartdate.text .activeconnection = conn end 'create recordset set rs = cmd.execute 'str = txtstartdate.text 'exestr = "exec dbo.ultrasoundreport(" & str & ")" 'open recordset 'rs.open if not isempty(rs) rs.movefirst 'populate first row of sheet recordset's field name = 0 each fld in rs.fields sheet1.cells(1, + 1).value = rs.fields.item(i).name = + 1 next fld 'populate sheet data recordset sheet1.range("a49:q49").copyfromrecordset rs else msgbox "unable open recordset, or unable connect database.", vbcritical, "can't requested records" end if 'cleanup rs.close set rs = nothing conn.close set conn = nothing exitlbl: debug.print "error: " & err.number if err.number = 0 msgbox "done", vbokonly, "all done." end if exit sub errlbl: msgbox "error #: " & err.number & ", description: " & err.description, vbcritical, "error in openconnection()" exit sub resume exitlbl end sub
it works fine information , pass parameter sproc
what need insert each of field values specific cells in excel , not sure how that. has done before?
thank you
the following article provides different methods achieve that: http://support.microsoft.com/kb/246335
Comments
Post a Comment