Consulting

Results 1 to 2 of 2

Thread: Function doesn't return value correctly

  1. #1

    Function doesn't return value correctly

    Hi,

    I have a function to determine the last insert id at mysql. Here is the function:

    [vba]
    Function GetInsertId(cnVerbinding As ADODB.Connection) As String
    Dim qryLastid As String, insertid As String
    Dim rsLastid As ADODB.Recordset

    qryLastid = "select last_insert_id()"
    Set rsLastid = New ADODB.Recordset
    rsLastid.Open qryLastid, cnVerbinding, adOpenForwardOnly, adLockReadOnly, adCmdText
    If Not rsLastid.EOF Then
    insertid = rsLastid.Fields(0).Value
    End If

    GetInsertId = insertid
    End Function
    [/vba]
    When I output the variable value of insertid within the function, I have the correct value. When I output the variable after calling the function, the function returns 0 or sometimes it doesn't return out of the function.

    Anyone knows what causes this problem?

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Is this specific to Outlook? There are forums for Excel and Access here as well:

    http://www.vbaexpress.com/forum/forumdisplay.php?f=17
    http://www.vbaexpress.com/forum/forumdisplay.php?f=16
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

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