Passing TableDef As a Parameter (correct version) 
Author Message
 Passing TableDef As a Parameter (correct version)

Sorry about posting twice but I quoted the wrong error message in the
previous post.

I have declared a TableDef and have created a new table using it.  I now
want to pass the TableDef variable to a function which will add fields to
it:

    Dim NewTable As TableDef

    // code to create table

    Add_Generic_Fields(NewTable)

Public Sub Add_Generic_Fields (Table As TableDef)

    // code

End Sub

When I try to call the func I get the error "Type Mismatch"

I am sure it is dead simple but it would be great if someone could let me
know how to do this.

Cheers

Ken
(please reply to author)



Sat, 25 Nov 2000 03:00:00 GMT  
 Passing TableDef As a Parameter (correct version)

Are you sure that when you call the function your NewTable variable is
set to an existing Tabledef? It won't hurt to use .Refresh method on
db.TableDefs before you call the function. I think it gives you the
error because the value of NewTable is Nothing.

HTH, Dimitri

Quote:

> Sorry about posting twice but I quoted the wrong error message in the
> previous post.

> I have declared a TableDef and have created a new table using it.  I now
> want to pass the TableDef variable to a function which will add fields to
> it:

>     Dim NewTable As TableDef

>     // code to create table

>     Add_Generic_Fields(NewTable)

> Public Sub Add_Generic_Fields (Table As TableDef)

>     // code

> End Sub

> When I try to call the func I get the error "Type Mismatch"

> I am sure it is dead simple but it would be great if someone could let me
> know how to do this.

> Cheers

> Ken
> (please reply to author)



Sat, 25 Nov 2000 03:00:00 GMT  
 Passing TableDef As a Parameter (correct version)

Oh, I just read your second post with the correct error message.  Now I can
state with certainty that the fact that you are calling your sub with the
line:

Add_Generic_Fields(NewTable)

when you should be using

Add_Generic_Fields NewTable

is precisely the cause of your problem.

Alden


Quote:
>Sorry about posting twice but I quoted the wrong error message in the
>previous post.

>I have declared a TableDef and have created a new table using it.  I now
>want to pass the TableDef variable to a function which will add fields to
>it:

>    Dim NewTable As TableDef

>    // code to create table

>    Add_Generic_Fields(NewTable)

>Public Sub Add_Generic_Fields (Table As TableDef)

>    // code

>End Sub

>When I try to call the func I get the error "Type Mismatch"

>I am sure it is dead simple but it would be great if someone could let me
>know how to do this.

>Cheers

>Ken
>(please reply to author)



Sun, 26 Nov 2000 03:00:00 GMT  
 Passing TableDef As a Parameter (correct version)

Quote:

>Oh, I just read your second post with the correct error message.  Now I can
>state with certainty that the fact that you are calling your sub with the
>line:

>Add_Generic_Fields(NewTable)

>when you should be using

>Add_Generic_Fields NewTable

>is precisely the cause of your problem.

I got my code top work by passing an integer value as follows

        Add_Generic_Fields(100)

    With a sub declarartion of:

        Public Sub Add_Generic_Fields(test As Integer)

So I do not know what the problem is now.

Cheers

Ken



Sun, 26 Nov 2000 03:00:00 GMT  
 Passing TableDef As a Parameter (correct version)

How about reading my reply that you just replied to, and trying what I
suggested.  I guess I didn't really EXPLAIN the cause of your problem, if
that was what you were looking for.  So here:

When you put the parentheses around the argument, like I told you you are
not supposed to, the argument is not interpreted correctly unless it
evaluates to either a number or a string, but not an object pointer.  So
when you changed the Sub so it would accept an integer it still works.  Also
notice that the code editor automatically puts a space before the argument:

Add_Generic_Fields (100)

This is because this is what it expects by the way you are calling the
procedure.
But when your Sub expects a TableDef as an argument:

Add_Generic_Fields (NewTable)

The expression (NewTable) actually evaluates to the Fields collection of the
NewTable TableDef object, not the object itself (I just tested this; I have
no idea why this happens - it just does; maybe one of the professional gurus
knows, but I don't).

So while the above method of calling your subroutine is not valid, the
following methods are:

Add_Generic_Fields NewTable

Call Add_Generic_Fields(NewTable)

Good luck,

Alden


Quote:


>>Oh, I just read your second post with the correct error message.  Now I
can
>>state with certainty that the fact that you are calling your sub with the
>>line:

>>Add_Generic_Fields(NewTable)

>>when you should be using

>>Add_Generic_Fields NewTable

>>is precisely the cause of your problem.

>I got my code top work by passing an integer value as follows

>        Add_Generic_Fields(100)

>    With a sub declarartion of:

>        Public Sub Add_Generic_Fields(test As Integer)

>So I do not know what the problem is now.

>Cheers

>Ken



Sun, 26 Nov 2000 03:00:00 GMT  
 Passing TableDef As a Parameter (correct version)

The reason that putting an TableDef in parentheses when passing it into a
proc will pass in the Fields collection is that the parens say "evaluate me"
and when you eval a TableDef object you get its default... which is the
fields collection.

Michael


Quote:
>How about reading my reply that you just replied to, and trying what I
>suggested.  I guess I didn't really EXPLAIN the cause of your problem, if
>that was what you were looking for.  So here:

>When you put the parentheses around the argument, like I told you you are
>not supposed to, the argument is not interpreted correctly unless it
>evaluates to either a number or a string, but not an object pointer.  So
>when you changed the Sub so it would accept an integer it still works.
Also
>notice that the code editor automatically puts a space before the argument:

>Add_Generic_Fields (100)

>This is because this is what it expects by the way you are calling the
>procedure.
>But when your Sub expects a TableDef as an argument:

>Add_Generic_Fields (NewTable)

>The expression (NewTable) actually evaluates to the Fields collection of
the
>NewTable TableDef object, not the object itself (I just tested this; I have
>no idea why this happens - it just does; maybe one of the professional
gurus
>knows, but I don't).

>So while the above method of calling your subroutine is not valid, the
>following methods are:

>Add_Generic_Fields NewTable

>Call Add_Generic_Fields(NewTable)

>Good luck,

>Alden




>>>Oh, I just read your second post with the correct error message.  Now I
>can
>>>state with certainty that the fact that you are calling your sub with the
>>>line:

>>>Add_Generic_Fields(NewTable)

>>>when you should be using

>>>Add_Generic_Fields NewTable

>>>is precisely the cause of your problem.

>>I got my code top work by passing an integer value as follows

>>        Add_Generic_Fields(100)

>>    With a sub declarartion of:

>>        Public Sub Add_Generic_Fields(test As Integer)

>>So I do not know what the problem is now.

>>Cheers

>>Ken



Fri, 01 Dec 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Passing TableDef parameters - Access 95

2. Correct way to pass a datetime parameter to a crystal report

3. Question about passing parameters (Correted version!)

4. DBEngine.version result is not correct

5. Whats slow about this code? (correct version)

6. Forcing Correct Assembly Version

7. COM - accessing the correct class version in VB Script

8. help !!!bug in inetcomm.dll, but corrected in version 6.0.2600.0 so have question

9. passing parameter to a parameter query

10. Passing Parameters to stored parameter queries using VB 5's Data Controls

11. passing optional parameters to the parameters collection

12. How to install correct language version of MDAC ?

 

 
Powered by phpBB® Forum Software