run time error '13': Type Mismatch when populating a recordset

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

does anyone know why this statement creates the above
error message:

Set rsteMailAddresses = dbf.OpenRecordset("SELECT
DISTINCT [tblMailingList].[eaddress] FROM
[tblMailingList];", dbOpenSnapshot)

I've dim'ed the recordset. i've never had this problem
in access 97 or 2000. Access 2002 doesn't like that stmt.

Thanks,

JIM
 
I've checked my referneces and am using DAO 3.6. I am
able to connect to the recordset but get another error
message as I try to retrieve a field value.

The following string is used to retrieve the value:

varSendTo = rsteMailAddresses.Fields(1).Value

The error message now is: Runtime Error 3265, Item not
found in this collection.

Here's the code snipet:

Sub sndMail()

Dim dbf As DAO.Database
Dim rsteMailAddresses As DAO.Recordset


Dim varSendTo As String

Set dbf = CurrentDb
Set rsteMailAddresses = dbf.OpenRecordset("SELECT
DISTINCT [tblMailingList].[eaddress] FROM
[tblMailingList];", dbOpenSnapshot)

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder
(olFolderOutbox)
Set myNewFolder = myFolder.Folders("PressReleases")
Set myitem = myNewFolder.Items("Taxconnect Launches new
Web Site")

With rsteMailAddresses

Do While .EOF = False

If .EOF Then
Exit Do
Else
varSendTo = rsteMailAddresses.Fields(1).Value

myitem.Copy
Set myRecipient = myitem.Recipients.Add(varSendTo)
myitem.Send
.MoveNext
End If

Loop

End With
End Sub



The code I'm working on is pass an email address, one at
a time to Outlook, and send an email.

-----Original Message-----
I'm assuming dbf has been declared as a Database, and that you're not having
any problems with setting it. That implies you set a reference to DAO 3.6
(Microsoft DAO 3.6 Object Library). When you did that, did you remove the
reference to ADO (Microsoft ActiveX Data Objects 2.x)?

If not, how have you declared rsteMailAddresses? 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

--
Doug Steele, Microsoft Access MVP



Jim said:
does anyone know why this statement creates the above
error message:

Set rsteMailAddresses = dbf.OpenRecordset("SELECT
DISTINCT [tblMailingList].[eaddress] FROM
[tblMailingList];", dbOpenSnapshot)

I've dim'ed the recordset. i've never had this problem
in access 97 or 2000. Access 2002 doesn't like that stmt.

Thanks,

JIM


.
 
varSendTo = rsteMailAddresses.Fields(1).Value
is referencing a non-existing second column

use rsteMailAddresses.Fields(0).Value
-----Original Message-----
I've checked my referneces and am using DAO 3.6. I am
able to connect to the recordset but get another error
message as I try to retrieve a field value.

The following string is used to retrieve the value:

varSendTo = rsteMailAddresses.Fields(1).Value

The error message now is: Runtime Error 3265, Item not
found in this collection.

Here's the code snipet:

Sub sndMail()

Dim dbf As DAO.Database
Dim rsteMailAddresses As DAO.Recordset


Dim varSendTo As String

Set dbf = CurrentDb
Set rsteMailAddresses = dbf.OpenRecordset("SELECT
DISTINCT [tblMailingList].[eaddress] FROM
[tblMailingList];", dbOpenSnapshot)

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder
(olFolderOutbox)
Set myNewFolder = myFolder.Folders("PressReleases")
Set myitem = myNewFolder.Items("Taxconnect Launches new
Web Site")

With rsteMailAddresses

Do While .EOF = False

If .EOF Then
Exit Do
Else
varSendTo = rsteMailAddresses.Fields(1).Value

myitem.Copy
Set myRecipient = myitem.Recipients.Add(varSendTo)
myitem.Send
.MoveNext
End If

Loop

End With
End Sub



The code I'm working on is pass an email address, one at
a time to Outlook, and send an email.

-----Original Message-----
I'm assuming dbf has been declared as a Database, and that you're not having
any problems with setting it. That implies you set a reference to DAO 3.6
(Microsoft DAO 3.6 Object Library). When you did that, did you remove the
reference to ADO (Microsoft ActiveX Data Objects 2.x)?

If not, how have you declared rsteMailAddresses? 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

--
Doug Steele, Microsoft Access MVP



Jim said:
does anyone know why this statement creates the above
error message:

Set rsteMailAddresses = dbf.OpenRecordset("SELECT
DISTINCT [tblMailingList].[eaddress] FROM
[tblMailingList];", dbOpenSnapshot)

I've dim'ed the recordset. i've never had this problem
in access 97 or 2000. Access 2002 doesn't like that stmt.

Thanks,

JIM


.
.
 
Thanks, never tested the 0 but it fixes the issue.
-----Original Message-----
varSendTo = rsteMailAddresses.Fields(1).Value
is referencing a non-existing second column

use rsteMailAddresses.Fields(0).Value
-----Original Message-----
I've checked my referneces and am using DAO 3.6. I am
able to connect to the recordset but get another error
message as I try to retrieve a field value.

The following string is used to retrieve the value:

varSendTo = rsteMailAddresses.Fields(1).Value

The error message now is: Runtime Error 3265, Item not
found in this collection.

Here's the code snipet:

Sub sndMail()

Dim dbf As DAO.Database
Dim rsteMailAddresses As DAO.Recordset


Dim varSendTo As String

Set dbf = CurrentDb
Set rsteMailAddresses = dbf.OpenRecordset("SELECT
DISTINCT [tblMailingList].[eaddress] FROM
[tblMailingList];", dbOpenSnapshot)

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder
(olFolderOutbox)
Set myNewFolder = myFolder.Folders("PressReleases")
Set myitem = myNewFolder.Items("Taxconnect Launches new
Web Site")

With rsteMailAddresses

Do While .EOF = False

If .EOF Then
Exit Do
Else
varSendTo = rsteMailAddresses.Fields(1).Value

myitem.Copy
Set myRecipient = myitem.Recipients.Add (varSendTo)
myitem.Send
.MoveNext
End If

Loop

End With
End Sub



The code I'm working on is pass an email address, one at
a time to Outlook, and send an email.

-----Original Message-----
I'm assuming dbf has been declared as a Database, and that you're not having
any problems with setting it. That implies you set a reference to DAO 3.6
(Microsoft DAO 3.6 Object Library). When you did that, did you remove the
reference to ADO (Microsoft ActiveX Data Objects 2.x)?

If not, how have you declared rsteMailAddresses? 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

--
Doug Steele, Microsoft Access MVP



does anyone know why this statement creates the above
error message:

Set rsteMailAddresses = dbf.OpenRecordset("SELECT
DISTINCT [tblMailingList].[eaddress] FROM
[tblMailingList];", dbOpenSnapshot)

I've dim'ed the recordset. i've never had this problem
in access 97 or 2000. Access 2002 doesn't like that stmt.

Thanks,

JIM


.
.
.
 
Back
Top