homework help needed: passing a recordset as a parameter 
Author Message
 homework help needed: passing a recordset as a parameter

Hi people,

I'm a student in need of help. In Access 2000, I'm trying to print out a
Word document containing information from a query. I 'm trying to pass a
recordset to the VBA sub that creates the document, but I get a type
mismatch error. This is not the actual code but it has the same problem as
the real code. tblResults is  a table, as one would expect. I think I might
not understand recordsets very well yet, and that is why I'm not writing the
code correctly.  Anyway, help would be appreciated.

Public Sub testing()
    testing2(CurrentDb!tblResults)            ' type mismatch error here
End Sub

Public Sub testing2(recTest As Recordset)
    Debug.Print "The count is  " & recTest.RecordCount
End Sub



Wed, 24 Nov 2004 13:46:50 GMT  
 homework help needed: passing a recordset as a parameter
Referring to a table like that does not create a recordset. You need to
explicity create it using CreateRecordset.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele


Quote:
> Hi people,

> I'm a student in need of help. In Access 2000, I'm trying to print out a
> Word document containing information from a query. I 'm trying to pass a
> recordset to the VBA sub that creates the document, but I get a type
> mismatch error. This is not the actual code but it has the same problem as
> the real code. tblResults is  a table, as one would expect. I think I
might
> not understand recordsets very well yet, and that is why I'm not writing
the
> code correctly.  Anyway, help would be appreciated.

> Public Sub testing()
>     testing2(CurrentDb!tblResults)            ' type mismatch error here
> End Sub

> Public Sub testing2(recTest As Recordset)
>     Debug.Print "The count is  " & recTest.RecordCount
> End Sub



Wed, 24 Nov 2004 18:55:39 GMT  
 homework help needed: passing a recordset as a parameter


Quote:
> Referring to a table like that does not create a recordset. You need to
> explicity create it using CreateRecordset.

Typo alert:  I think Doug meant "OpenRecordset".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)



Wed, 24 Nov 2004 22:38:21 GMT  
 homework help needed: passing a recordset as a parameter



Quote:
> Referring to a table like that does not create a recordset. You need to
> explicity create it using CreateRecordset.

Thanks, Douglas, I suspected that.  I still get the same errror message with
this code, though:

Public Sub testing()
    Dim rec As Recordset
    Dim db As Database
    Set db = CurrentDb()
    Set rec = db.OpenRecordset("tblresults")
    testing2 (rec)
End Sub

Public Sub testing2(recTest As Recordset)
    Debug.Print "The count is  " & recTest.RecordCount
End Sub

Tim B



Thu, 25 Nov 2004 00:04:40 GMT  
 homework help needed: passing a recordset as a parameter


Quote:

> Thanks, Douglas, I suspected that.  I still get the same errror message
with
> this code, though:

> Public Sub testing()
>     Dim rec As Recordset
>     Dim db As Database
>     Set db = CurrentDb()
>     Set rec = db.OpenRecordset("tblresults")
>     testing2 (rec)
> End Sub

> Public Sub testing2(recTest As Recordset)
>     Debug.Print "The count is  " & recTest.RecordCount
> End Sub

> Tim B

Well, this does work:

Set rec = db.OpenRecordset("tblresults")
testing2  rec

the parentheses were the problem



Thu, 25 Nov 2004 01:25:57 GMT  
 homework help needed: passing a recordset as a parameter

Quote:

>I'm a student in need of help. In Access 2000, I'm trying to print out a
>Word document containing information from a query. I 'm trying to pass a
>recordset to the VBA sub that creates the document, but I get a type
>mismatch error. This is not the actual code but it has the same problem as
>the real code. tblResults is  a table, as one would expect. I think I might
>not understand recordsets very well yet, and that is why I'm not writing the
>code correctly.  Anyway, help would be appreciated.

>Public Sub testing()
>    testing2(CurrentDb!tblResults)            ' type mismatch error here
>End Sub

>Public Sub testing2(recTest As Recordset)
>    Debug.Print "The count is  " & recTest.RecordCount
>End Sub

It looks like you have to straighten out your References to
DAO and ADO.  Open any code module (or the debug window) and
use Tools - References.  Make sure DAO is checked, and if
you don't have a need for ADO uncheck that one.  If You must
use both libraries, then qualify the objects that occur in
both libraries (e.g. Dim rs As DAO.Recordset).

--
Marsh
MVP [MS Access]



Thu, 25 Nov 2004 01:23:37 GMT  
 homework help needed: passing a recordset as a parameter

Quote:


> > Referring to a table like that does not create a recordset. You need to
> > explicity create it using CreateRecordset.

> Typo alert:  I think Doug meant "OpenRecordset".

Thanks, Dirk

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele



Thu, 25 Nov 2004 02:55:12 GMT  
 homework help needed: passing a recordset as a parameter

Quote:

> Well, this does work:

> Set rec = db.OpenRecordset("tblresults")
> testing2  rec

> the parentheses were the problem

Sorry: should have caught that as well.

When you're calling a Subroutine, you either don't use parentheses, or you
use a Call statement:

    Call Testing2(rec)

Glad you got it working.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele



Thu, 25 Nov 2004 02:56:59 GMT  
 homework help needed: passing a recordset as a parameter

Quote:

>Well, this does work:

>Set rec = db.OpenRecordset("tblresults")
>testing2  rec

>the parentheses were the problem

Ah, of course.  Sorry for going off on a tangent, I should
have caught that.
--
Marsh


Thu, 25 Nov 2004 03:12:25 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Help: passing a recordset as parameters

2. Newbie needs help w/homework - VisData

3. VB Beginner Needs Help with Homework

4. need help with homework project!

5. Need help, homework question.

6. Students needing help with VB Homework?

7. VB Beginner Needs Help with Homework

8. HELP..i need a pell checket for my text editor(homework/final)

9. need help with homework!

10. Need help passing query parameters in a url

11. Urgent help needed in parameter passing

12. Need Help passing Parameters to SQL query in a VB dataenviroment

 

 
Powered by phpBB® Forum Software