sql - VBA: Loop isn't working as it should -
being new here don't know if can state question clear, i'll try.
i have vba code extracts information access database excel sheet in relation excel sheet. , being new vba coding don't know how or correct method i'm using.
my problem loop that's supposed work when 'fam' equal 'z' value in column. so, in more detail, column d worksheet "gbe..." contains first 2 values of numbers column b, , when give input keyboard value stored in 'fam' code supposed search in entire column value , continue extract database data i'm asking for, loop doesn't stop when fam <> z.
i hope can me, i've learned vba here, ran out of ideas.
sub dateinitiale() dim data date 'dim codprodus, codrola variant dim i, j, k, m, n, s, x, y, z2, z3 integer dim z variant dim olddb database, oldws workspace set oldws = dbengine.workspaces(0) set olddb = oldws.opendatabase("c:\busdata\rfyt\xxg\_lgi\data\fytmaes.mdb") 'cale bd pentru importul datelor cells(1, 1) = "cod produs" cells(1, 2) = "nr rola" cells(1, 3) = "masina " cells(1, 4) = "data inceput" cells(1, 5) = "data sfarsit" fam = application.inputbox("introduceti familia cab", "famcab search") if fam = false exit sub z = worksheets("gbe03407e").cells(2, 4).value x = 2 y = 2 z2 = 2 until z = "" z = worksheets("gbe03407e").cells(z2, 4).value z3 = z2 while fam = z codrola = worksheets("gbe03407e").cells(z3, 2).value cells(y, 2).value = codrola cells(y, 1).value = codprodus ' write values read menu cells sql = "select initra, fintra, codmaq, codsuc tbltraza numser '" & codrola & "' , (tiptra='f' or tiptra='fa' or tiptra='fd' or tiptra='ff' or tiptra='fm' or tiptra='ft' or tiptra='fc' or tiptra='fk' or tiptra='fn' or tiptra='fq' or tiptra='fr')order fecmov" set rs = olddb.openrecordset(sql) on error resume next rs.movefirst until rs.eof cells(y, 1).value = rs("codsuc") cells(y, 3).value = rs("codmaq") cells(y, 4).value = rs("initra") cells(y, 5).value = rs("fintra") rs.movenext loop x = x + 1 y = y + 8 z3 = z3 + 1 loop z2 = z2 + 1 loop end sub
it seems you're not updating either z or fam inside loop:
do while fam = z
which lead infinite loop. if understand correctly you're trying do, should replace
if fam = z
also, want test if query returns value. this:
if fam = z ... set rs = olddb.openrecordset(sql) if not rs.eof ... end if ... end if
Comments
Post a Comment