Counting number of records in query in VBA - problems opening the recordset.

odin1701

Registered User.
Local time
Today, 13:02
Joined
Dec 6, 2006
Messages
526
Here is the code that I have so far:


Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strVar As String

strVar = [Forms]![frmDateSelection3].[QueryDate].[Value]

strSQL = "SELECT * FROM qryCustInfo WHERE ((qryCustInfo.[Date Entered System])=#" & strVar & "#);"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

If rs.RecordCount = 0 Then

    MsgBox "There are no records for this date", vbOKOnly
    DoCmd.Close acForm, "frmDateSelection3"
    
Else

DoCmd.TransferSpreadsheet acExport, , "qryCustInfo", BrowseSaveXLS(CurDir(), "Save As")
DoCmd.Close acForm, "frmDateSelection3"

End If


I don't see what I'm doing wrong - but the error I get is:

Runtime error 3061

Too few paramaters. Expected 1.

I can paste that same SQL string (except putting the value of the variable in) into a regular query in Access and it works just fine.

I don't understand what I'm doing wrong.

All this is supposed to do is export a spreadsheet for a date specified in a form, and before doing the export, notify you if there are no records instead of exporting a sheet with nothing in it.

Help!
 
Okay - nevermind.

I deleted the query and recreated it exactly the same way and it works perfect now.

:confused:
 
Have you tried using a MsgBox on strSQL to see what you are asking Access to do?
 

Users who are viewing this thread

Back
Top Bottom