Recordset: What am I doing wrong? 
Author Message
 Recordset: What am I doing wrong?

I am trying to create a recordset using a query in the current database
as follows:

Dim ContactsDb As Recordset
Dim SQLText As String
SQLText = "SELECT * FROM [TreatmentQueryWithAllTreatersInfo] WHERE
[CaseID] = " & Me!CaseID
Set ContactsDb = CurrentDb.OpenRecordset(SQLText)

I keep getting a Run-time error 13 (type mismatch).  What am I doing
wrong?  (CaseID is a long number field.)



Tue, 09 Aug 2005 05:59:03 GMT  
 Recordset: What am I doing wrong?
Should it look like this:

if caseid is a number - SQLText = "SELECT * FROM
[TreatmentQueryWithAllTreatersInfo] WHERE [CaseID] = " & Me!CaseID & ";"

if caseid is text - SQLText = "SELECT * FROM
[TreatmentQueryWithAllTreatersInfo] WHERE
[CaseID] =  '" & Me!CaseID & "';"


Quote:
> I am trying to create a recordset using a query in the current database
> as follows:

> Dim ContactsDb As Recordset
> Dim SQLText As String
> SQLText = "SELECT * FROM [TreatmentQueryWithAllTreatersInfo] WHERE
> [CaseID] = " & Me!CaseID
> Set ContactsDb = CurrentDb.OpenRecordset(SQLText)

> I keep getting a Run-time error 13 (type mismatch).  What am I doing
> wrong?  (CaseID is a long number field.)



Tue, 09 Aug 2005 06:22:22 GMT  
 Recordset: What am I doing wrong?

Quote:
> I am trying to create a recordset using a query in the current database
> as follows:

> Dim ContactsDb As Recordset
> Dim SQLText As String
> SQLText = "SELECT * FROM [TreatmentQueryWithAllTreatersInfo] WHERE
> [CaseID] = " & Me!CaseID
> Set ContactsDb = CurrentDb.OpenRecordset(SQLText)

> I keep getting a Run-time error 13 (type mismatch).  What am I doing
> wrong?  (CaseID is a long number field.)

If you are using Access 2000, or higher, you need to add a reference to the DAO
Library (see http://support.microsoft.com/default.aspx?scid=KB;EN-US;225962 -
add a "Type Mismatch" error to those listed in the article) and then
disambiguate the Recordset object:

    Dim ContactsDb As DAO.Recordset

--
Bruce M. Thompson, Microsoft Access MVP

Quote:
>>No Email, Please. Keep all communications

    within the newsgroups so that all might benefit.<<


Tue, 09 Aug 2005 06:47:12 GMT  
 Recordset: What am I doing wrong?
I think that the SQL statement is not the problem: the problem is that the
OpenRecordset command is wrong.  I want to create some sort of temporary
recordset in memory so that I can work on its records.
Quote:

> Should it look like this:

> if caseid is a number - SQLText = "SELECT * FROM
> [TreatmentQueryWithAllTreatersInfo] WHERE [CaseID] = " & Me!CaseID & ";"

> if caseid is text - SQLText = "SELECT * FROM
> [TreatmentQueryWithAllTreatersInfo] WHERE
> [CaseID] =  '" & Me!CaseID & "';"



> > I am trying to create a recordset using a query in the current database
> > as follows:

> > Dim ContactsDb As Recordset
> > Dim SQLText As String
> > SQLText = "SELECT * FROM [TreatmentQueryWithAllTreatersInfo] WHERE
> > [CaseID] = " & Me!CaseID
> > Set ContactsDb = CurrentDb.OpenRecordset(SQLText)

> > I keep getting a Run-time error 13 (type mismatch).  What am I doing
> > wrong?  (CaseID is a long number field.)



Tue, 09 Aug 2005 07:26:53 GMT  
 Recordset: What am I doing wrong?
Nothing wrong with the semi-colon at the end of each SQL String but you
don't need the semi-colon and therefore you can omit it.

Bruce, as usual, pointed to the correct problem and solution in this case.

--
HTH
Van T. Dinh
MVP (Access)


Quote:
> Should it look like this:

> if caseid is a number - SQLText = "SELECT * FROM
> [TreatmentQueryWithAllTreatersInfo] WHERE [CaseID] = " & Me!CaseID & ";"

> if caseid is text - SQLText = "SELECT * FROM
> [TreatmentQueryWithAllTreatersInfo] WHERE
> [CaseID] =  '" & Me!CaseID & "';"



> > I am trying to create a recordset using a query in the current database
> > as follows:

> > Dim ContactsDb As Recordset
> > Dim SQLText As String
> > SQLText = "SELECT * FROM [TreatmentQueryWithAllTreatersInfo] WHERE
> > [CaseID] = " & Me!CaseID
> > Set ContactsDb = CurrentDb.OpenRecordset(SQLText)

> > I keep getting a Run-time error 13 (type mismatch).  What am I doing
> > wrong?  (CaseID is a long number field.)



Tue, 09 Aug 2005 07:27:40 GMT  
 Recordset: What am I doing wrong?

Quote:
> Bruce, as usual, pointed to the correct problem and solution in this case.

Flattery will get you everywhere, Van.    <BG>

--
Bruce M. Thompson, Microsoft Access MVP

Quote:
>>No Email, Please. Keep all communications

    within the newsgroups so that all might benefit.<<


Tue, 09 Aug 2005 07:38:14 GMT  
 Recordset: What am I doing wrong?
Except with my wife, especially when I flatter her while I sit in front of
the computer answering NG posts.

Cheers
Van



Quote:
> > Bruce, as usual, pointed to the correct problem and solution in this
case.

> Flattery will get you everywhere, Van.    <BG>

> --
> Bruce M. Thompson, Microsoft Access MVP

> >>No Email, Please. Keep all communications
>     within the newsgroups so that all might benefit.<<



Wed, 10 Aug 2005 07:48:23 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Recordset object, what am i doing wrong?

2. ADO opens database, but not a recordset- What am I doing wrong?

3. What am I doing wrong??

4. What am I doing wrong?

5. Help with syntax. What am I doing wrong

6. What am I doing wrong?

7. What am I doing wrong?

8. What am I doing wrong?

9. Please tell me what I am doing wrong - DAO parameter Append Query :(

10. What am I doing wrong? -MultiSelect List box

11. Select Case - What am I doing wrong?

12. What am I doing wrong (easy).

 

 
Powered by phpBB® Forum Software