sql - Populate Excel userform listbox with query data - listbox is blank -
i'm attempting populate listbox on userform in excel document query sql server, listbox blank.
i'm trying list of locations populate use define parameters follow on query.
here code:
option explicit sub populate_listbox_from_sql() dim cnt adodb.connection dim rst adodb.recordset dim stdb string, stconn string, stsql string dim xlcalc xlcalculation dim vadata variant dim k long 'set sql connection , connection string set cnt = new adodb.connection stconn = "provider=sqloledb.1;integrated security=sspi;persist security info=false;initial catalog=dw;data source=use-rptdw-00;use procedure prepare=1;auto translate=true;" _ & "packet size=4096;workstation id=pi-l-c03rtrd;use encryption data=false;tag column collation when possible=false" cnt.connectionstring = stconn 'your sql statement stsql = "select ldesc fin.location order ldesc" cnt .cursorlocation = aduseclient 'necesary creating disconnected recordset. .open stconn 'open connection. 'instantiate recordsetobject , execute sql-state. set rst = .execute(stsql) end rst set .activeconnection = nothing 'disconnect recordset. k = .fields.count 'populate array whole recordset. vadata = .getrows end 'close connection. cnt.close 'manipulate listbox's properties , show form. userform1 .combobox1 .clear .boundcolumn = k .list = application.transpose(vadata) .listindex = -1 end .show vbmodeless end 'release objects memory. set rst = nothing set cnt = nothing end sub
maybe i'm putting code in wrong place? have under base vba code userform. or maybe need set properties listbox itself?
i'm pretty new vba appreciated
never mind. figured out. wasn't making explicit call function. although, "run-time error '400': form displayed; can't show modally" error.
any idea how stop happening?
Comments
Post a Comment