Honestly, the only problem I see with your code is that you don't initialize your variable intCount.
Find the line that says:
Code:
Do Until intCount = rst.Fields.Count
And add this just before it:
If you do this for both functions, it should solve your problem.
As for your question on the Query, there are several ways to do it. Access has an actual Query Object that you can use but the easiest way is to jump straight to a Recordset with it.
Option 1 - Using QueryDefs (not recommended):
Code:
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
' Save your Access Query Object to a QueryDefs variable!
Set qdf = CurrentDb().QueryDefs("myQuery")
' Now dump the results of your saved query into a Recordset.
Set rst = CurrentDb().OpenRecordset(qdf.SQL, dbOpenSnapshot)
' Your code goes here
' Close our our variables
qdf.Close
rst.Close
Set qdf = Nothing
Set rst = Nothing
Option 2 - Using Recordsets (recommended):
Code:
Dim rst As DAO.Recordset
' ONLY USE ONE OF THE FOLLOWING TWO LINES - THEY BOTH DO THE SAME THING
' Using a saved Query.
Set rst = CurrentDb().OpenRecordset("myQuery", dbOpenSnapshot)
' Using straight SQL code.
Set rst = CurrentDb().OpenRecordset("SELECT * FROM myTable WHERE myField=1", dbOpenSnapshot)
' Your code goes here
' Close our our variables
rst.Close
Set rst = Nothing
Obviously I recommend using the second method since you will still need to use a Recordset at some point in your code.