Results 1 to 4 of 4

Thread: Converting Access Query To VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Posts
    2
    I have an access query which looks something like this:

    SELECT batting.player, careerteams(batting.player), stuff
    FROM batting
    WHERE batting.seg = 0

    The careerteams is actually a function within access that returns back all the teams a player ever played for.

    When I try to use the query in VB (regardless of where or how), it tells me its an invalid function call.

    I've tried copying the function over to VB and having it be public in a module within my program, and still can't seem to get it to convert.

    Is this possible with VB and I'm just missing something?

    Thanks,
    Chad

  2. #2
    Lively Member dlm's Avatar
    Join Date
    Oct 2000
    Location
    Geraardsbergen(Belgium)
    Posts
    91
    Hi

    try something like this...

    Code:
    Dim MySQL as string
    
    MySQL = "SELECT batting.player, " & careerteams(batting.player) & ", stuff FROM batting WHERE batting.seg = 0"
    If you can solve the problem, why worrying about it…
    If you can’t solve the problem, worrying won’t help…

    De la Motte Günther

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    As far as I know, you cannot use User Defined Functions (UDFs) in this way in VB. The best way is to run a simple SELECT and then use the function on the resultant recordset.


    e.g.
    base a recordset, rs, say, on:
    SELECT batting.player, "temp" As PlaceHolder, stuff FROM batting WHERE batting.seg = 0

    With rs Do
    Do Until .EOF
    .Edit
    !PlaceHolder = CareerTeams(!player)
    .Update
    .MoveNext
    Loop
    End With

    Change for ADO and add error checking as necessary.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Posts
    2

    Smile Thanks

    Shortly after my posting, I found in a book that I couldn't use the function in a VB query. Thanks for the workaround suggestion. That was going to be my next question.

    Chad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width