PDA

View Full Version : Function doesn't return value correctly



dubbelpunt
03-19-2012, 05:08 AM
Hi,

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


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

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?

JP2112
03-20-2012, 01:16 PM
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