Code Not Working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to clean up our application and have started a new mdb. I copied
and pasted this code into the new mdb. When I run this it crases and shows
that the rst = "nothing".

I have, I believe, linked and imported all the necessary forms, queries, and
tables that apply to this code

Set rst = CurrentDb.OpenRecordset("SELECT CompanyId from tblAlerts WHERE
ShipDate = #" & Date & "#")
If rst.RecordCount = 0 Then
CurrentDb.Execute "qryAddStdShipmentsForToday"
End If
rst.close
Set rst = Nothing
'GetNotes
Me.frmAlertsSub.Form!Airbill.SetFocus

Any ideas on why the rst = "nothing"
Would it be better to hard code the rst = tblAlerts ? If so please help
with syntax. I tried doing that am not apparently doing it correctly.

Thanks in advance for any help
 
cvegas said:
I am trying to clean up our application and have started a new mdb.
I copied and pasted this code into the new mdb. When I run this it
crases and shows that the rst = "nothing".

I have, I believe, linked and imported all the necessary forms,
queries, and tables that apply to this code

Set rst = CurrentDb.OpenRecordset("SELECT CompanyId from tblAlerts
WHERE ShipDate = #" & Date & "#")
If rst.RecordCount = 0 Then
CurrentDb.Execute "qryAddStdShipmentsForToday"
End If
rst.close
Set rst = Nothing
'GetNotes
Me.frmAlertsSub.Form!Airbill.SetFocus

Any ideas on why the rst = "nothing"
Would it be better to hard code the rst = tblAlerts ? If so please
help with syntax. I tried doing that am not apparently doing it
correctly.

Thanks in advance for any help

What's the nature of your "crash"? What error message do you get?

What version of Access are you using?

How is rst declared? If you're using Access 2000 or 2002, do you have a
reference set the Microsoft DAO 3.6 Object Library, and have you
declared rst As DAO.Recordset?
 
Thanks you for your response. Sorry I am using A2K

I get a type mismatch error and it stops on
 
How have you declared rst? Your code is using DAO, but by default, Access
2000 uses ADO.

Have you set a reference to DAO? With any code module open, select Tools |
References from the menu bar, scroll through the list of available
references until you find the one for Microsoft DAO 3.6 Object Library, and
select it. If you're not going to be using ADO, uncheck the reference to
Microsoft ActiveX Data Objects 2.1 Library

If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO recordset, you'll need to
use Dim rsCurr as DAO.Recordset (to guarantee an ADO recordset, you'd use
Dim rsCurr As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
 
Back
Top