What is wrong with this code

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi all,

I`m new to VBA,
This is my code:

Private Sub Form_Load()
Dim Rst As Recordset
Dim i As Variant
Set Rst = CurrentDb.OpenRecordset("Chartqry")
Set i = Rst.OpenRecordset.RecordCount

If i >0 Then
MsgBox "something"

End If
Rst.Close
Set Rst = Nothing

End Sub

I get "object required" error

Thanks,
Tom
 
Hi Tom,

Well, there's lots of things you could do to fix/improve that!

But it seems that all you are trying to do is show a message box if there
are any records in Chartqry (presumably an existing query). If that's all
you want to do, the following would be much simpler:

Private Sub Form_Load()
If dcount("*","Chartqry") > 0 Then
MsgBox "something"
End If
End Sub

HTH,

Rob
 
Thanks Rob,
That was very easy

Tom
Rob Parker said:
Hi Tom,

Well, there's lots of things you could do to fix/improve that!

But it seems that all you are trying to do is show a message box if there
are any records in Chartqry (presumably an existing query). If that's all
you want to do, the following would be much simpler:

Private Sub Form_Load()
If dcount("*","Chartqry") > 0 Then
MsgBox "something"
End If
End Sub

HTH,

Rob
 
Back
Top