Populate combobox access 2007 using vba with postgresql table -
i'm trying populate combobox records table filtered parent combobox. table want filter called muni , parent table called prov. related common field (muni has field called gid_prov contains prov gid each record) first combobox stores prov gid , shows prov name. both tables in database postgresql connected access dsn file using odbc. have tried many options, , none correct. first tried simple option. code useless now
private sub prov_change() muni.rowsourcetype = "table/query" muni.rowsource = "select * memoria.muni gid_provs =" & prov muni.requery muni.setfocus muni.text = "" end sub
prov name of parent combobox stores prov gid. , muni combobox want populate. other option tried creating query sql statement, code right now, tried openrecordsetoutput, not working. can access database , fields, can't populate combobox muni
private sub prov_change() dim odb dao.database dim ors dao.recordset dbconnect = "odbc;driver=postgresql ansi;uid=***;pwd=***;port=5432;server=127...;database=memoria_historica;dsn=c:\users\***" set odb = opendatabase("", false, false, dbconnect) dim sql string sql = "select gid,nombre memoria.municipios m m.gid_provs =" & prov & "order m.nombre;" set ors = odb.openrecordset(sql, dbopensnapshot, dbsqlpassthrough) me.muni2.rowsource = "" if ors.recordcount > 0 ors .movefirst .movenext while not .eof muni2.additem .fields("nombre").value .movenext loop end end sub
worked fine tih support of @thaippo. thanks
you can dao library.
you dao. database , dao. recordset like:
dim odb dao.database dim ors dao.recordset
your second block of codes work.
set odb = opendatabase("", false, false, dbconnect) dim sql string sql = "select m.nombre memoria.muni m,memoria.prov p st_within(m.the_geom,p.the_geom) , p.gid =" & prov ";" set ors = odb.openrecordset(sql) if ors.recordcount > 1 theb ors .movelast .movefirst while not.eof prov.additem . fields("nameoffieldsyouneed"). value .movenext loop end end if
and it's idea clear combox box before adding new items in it.
Comments
Post a Comment