Repost : Null recordset problem

  • Thread starter Thread starter George Papadopoulos
  • Start date Start date
G

George Papadopoulos

I have written the code below (courtesy of Nikos Yannacopoulos) :

Private Sub btnReport_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("query_Anafora_bash_aitias_blabhs")
On Error GoTo no_record

rst.MoveLast
On Error GoTo 0
rst.Close
Set rst = Nothing
Set db = Nothing

If IsDate(Me.From_Date) Then dtFrom_Date = Me.From_Date
If IsDate(Me.To_Date) Then dtTo_Date = Me.To_Date

If (Me.btnKakh_xrhsh) Then
DoCmd.OpenReport "Anafora_bash_aitias_blabhs_kakh_xrhsh", acViewPreview
Else
DoCmd.OpenReport "Anafora_bash_aitias_blabhs_fysiologikh_f8ora",
acViewPreview
End If

Exit Sub

no_record:
MsgBox ("Aai anYeceai aaanaoYo")

End Sub

The code now fails with a syntax error at the statement

Set rst = db.OpenRecordset("query_Anafora_bash_aitias_blabhs").

The error states that more arguments are needed. I had the idea that all
other arguments
to the OpenRecordset method were optional. Is this not the case?
 
George said:
I have written the code below (courtesy of Nikos Yannacopoulos) :

Private Sub btnReport_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("query_Anafora_bash_aitias_blabhs")
On Error GoTo no_record

rst.MoveLast
On Error GoTo 0
rst.Close
Set rst = Nothing
Set db = Nothing

If IsDate(Me.From_Date) Then dtFrom_Date = Me.From_Date
If IsDate(Me.To_Date) Then dtTo_Date = Me.To_Date

If (Me.btnKakh_xrhsh) Then
DoCmd.OpenReport "Anafora_bash_aitias_blabhs_kakh_xrhsh", acViewPreview
Else
DoCmd.OpenReport "Anafora_bash_aitias_blabhs_fysiologikh_f8ora",
acViewPreview
End If

Exit Sub

no_record:
MsgBox ("Aai anYeceai aaanaoYo")

End Sub

The code now fails with a syntax error at the statement

Set rst = db.OpenRecordset("query_Anafora_bash_aitias_blabhs").

The error states that more arguments are needed. I had the idea that all
other arguments
to the OpenRecordset method were optional. Is this not the case?

The arguments that it's looking for are probably in the
query. Are you sure the message isn't complaining about
too few **Parameters**?

When you open a recordset on a query with parameters, the
parameters are not automatically resolved the way they are
when you open the query directly or use it in a form or
report.
 
Back
Top