Help understanding truely strange error involving access query and filling cells

  • Thread starter Thread starter puff
  • Start date Start date
P

puff

An excel application I'm working on has developed a truely strange bug
that I'm having difficulty getting a handle on ... it is filling an
entire sheet with the number 53 for no apparent reason!?!?

The application queries an Access database with code like this:

Function Qry(tllocation As Range, sql As String) As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset

application.ThisWorkbook.Activate
Set db = OpenDatabase(ThisWorkbook.Path & "\MMR.mDB")
Set rs = db.OpenRecordset(sql)
rows = tllocation.cells(2, 1).CopyFromRecordset(rs)
db.Close
Set db = Nothing
Set rs = Nothing
Exit Function
End Function

The query retrievs 53 records (break point on Exit alows examination).
While sitting on the breakpoint the spreadsheet exhibits the expected
records. HOWEVER, a single step takes a long time during which the
status line displays "Filling Cells". When control returns to the
calling UDF ALL the sheet's cells contain 53!

I'm truely mystified. Has anyone any clues?

Thanks for any help.
 
Sometimes excel makes me just crazy ...

The calling code lookes like this

rows = Qry( ... )

and I had not declared rows (BAD puff). Now rows in this context is a
range containing ALL the rows on the active worksheet. Qry returns
it's record count, 53 and excel happily fills every cell of every row
with the value.

I shall now go and repeat over and over and over again "Thou shalt Dim
ALL your variables always. Thou shalt NOT use excell works ever!"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top