ms access - query returns a value, but ADODB.Recordset.fields("Value") = null -


i trying collate data 2 different servers, 1 sql , 1 access. admit access sql little shakey, 1 doesn't make sense me.

i firing query @ access database, have configured queries in both servers return single values function.

the query follows

bookquery =  "select sum(dbo_wipjobpost.lqtycomplete) [sum]" & vbcr & _ "from dbo_wipjobpost" & vbcr & _ "where dbo_wipjobpost.lmachine '**" & machno & "**'" & vbcr & _ "and dbo_wipjobpost.trndate between #" & format(stime, "dd-mmm-yyyy hh:mm:sss") & "# , #" & format(atime, "dd-mmm-yyyy hh:mm:sss") & "#" & vbcr & _ "or dbo_wipjobpost.lworkcentre '**" & machno & "**'" & vbcr & _ "and dbo_wipjobpost.trndate between #" & format(stime, "dd-mmm-yyyy hh:mm:sss") & "# , #" & format(atime, "dd-mmm-yyyy hh:mm:sss") & "#;" 

when run query directly against access database number returned under column "sum". in application calling automatically using function puts query database , column heading interested in

bstring = onerecord(bookquery, "access", "sum")

function onerecord(query string, db string, field string) 'function return single cell recordset  dim conn adodb.connection dim rec adodb.recordset dim constring string  constring = selectdb(db)  set conn = new adodb.connection set rec = new adodb.recordset  'open con string , run query conn.open constring  set rec = conn.execute(query)  'check records exist if not rec.eof  'return result onerecord = rec.fields(field) rec.close  else msgbox "no records" norecords = true end if  ' clean  if cbool(conn.state , adstateopen) conn.close set conn = nothing set rec = nothing  end function 

for reason once query , field placed in line

onerecord = rec.fields(field)

the highlighted prompt returns null. have tested query prints in 1 record function , works, have heading sum, reason doesn't work.

i think wildcards around machno, if specify distinct machine onerecord code works, wildcards not (i working off of older databases , random spaces in machine names etc common.)

can me take final steps this? feels close!


Comments

Popular posts from this blog

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -

php - Cannot override Laravel Spark authentication with own implementation -