Updating a Query that is changed by SQL code - Microsoft Community


using form display data in query. have button on form runs code changes criteria in query form displaying data from. however, both requery , refresh not refresh data. closing , reopening form, there efficient way keep data updated after changes made in query?

see nothing in code calls form's requery method.

plan display data multiple queries in form.  mean intend return single result table in form on basis of join or union of multiple queries?  or intend return result tables of queries independently in subforms within single parent form?  if former need call requery method of parent form; if latter need call requery method of relevant subform control in parent form's controls collection.

however, why go trouble of amending sql property of querydef object?  why not use sql statement directly form's (or subform's) recordsource property , assign amended string expression recordsource property?

alternatively, seem restricting query on basis of value of pn control in form, why not reference control parameter in query , call form's requery method reload recordset on basis of current value in pn control?  notice display partnumbers (plural), value of pn value list?  if can referenced parameter calling inparam , gettoken functions published microsoft:

'============================================================
' inparam() function heart of article. when
' query runs, function causes query parameter
' dialog box appear can enter list of values.
' values enter interpreted if you
' had entered them within parentheses of in() operator.
'============================================================
function inparam(fld, param)

    dim sttoken string
    'the following 2 lines optional, making queries
    'case-insensitive
    fld = ucase(fld)
    param = ucase(param)
    
    if isnull(fld) fld = ""
        while (len(param) > 0)
        sttoken = gettoken(param, ",")
        if sttoken = ltrim$(rtrim$(fld)) then
            inparam = -1
            exit function
        else
            inparam = 0
        end if
    loop

end function


function gettoken(stln, stdelim)
     
    dim idelim integer, sttoken string
    
    idelim = instr(1, stln, stdelim)
    
    if (idelim <> 0) then
        sttoken = ltrim$(rtrim$(mid$(stln, 1, idelim - 1)))
        stln = mid$(stln, idelim + 1)
    else
        sttoken = ltrim$(rtrim$(mid$(stln, 1)))
        stln = ""
    end if
    
    gettoken = sttoken
    
end function

in query inparam function called this:

inparam(partnum, forms!yourformname!pn)

returns boolean true rows value in partnum column 1 of values in comma separated value list in pn control.


Office / Access / Other/unknown / Office 2010



Comments

Popular posts from this blog

Windows 10 does not have any of my previous Windows 7 email address. - Microsoft Community