Access 2002: Problem in VB function

M

Michael Dekson

In this VB function I have "Run-time error '3151' and debug is located at
bold item (-->>).

If you know what I do wrong please help me to solve this problem.

Thanks





Public Function get_cjena_imp(p_vccid As Integer, p_datum As Date)

Dim RST As Recordset

Dim db As Database

Dim strSQL As String



If Not IsNull(p_vccid) And Not IsNull(p_datum) Then

Set db = CurrentDb

'strSQL = "SELECT P.CIJENA_IMPULSA FROM CRM_BIL_PARAMETRI AS P WHERE
P.VCC_ID= " & CStr(p_vccid) & " AND P.DATUM_OD=(SELECT MAX(P1.DATUM_OD) FROM
CRM_BIL_PARAMETRI P1 WHERE P1.VCC_ID = P.VCC_ID AND P1.DATUM_OD < " &
"cdate('" & CStr(p_datum) & "'));"

strSQL = "SELECT * FROM CRM_BIL_PARAMETRI"

'strSQL = "select * from stat"

-->> Set RST = db.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)

If RST.EOF And RST.BOF Then

Exit Function

End If



get_cjena_imp = RST![CIJENA_IMPULSA]

'db.Properties!AppTitle = "KASA - OPERATER: " & RST![Prezime]

'Application.RefreshTitleBar

RST.Close

Set db = Nothing

'PASS_OK = True

DoCmd.Close

Else

MsgBox "Funkcija get_cjena_imp: jedan od parametara je prazan",
vbCritical



End If



End Function
 
A

Arvin Meyer

You need to set a reference to the DAO library. If you also have the ADO
library referenced, you'll need to disambiguate your code.

First, from any code window go to Tools ... References, then set a reference
to "Microsoft DAO 3.6 Object Library"

Then change your code to disambiguate:

Dim RST As DAO.Recordset
Dim db As DAO.Database

Also make sure you set your Recordset variable to Nothing, as well as
closing it.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

Michael Dekson said:
In this VB function I have "Run-time error '3151' and debug is located at
bold item (-->>).

If you know what I do wrong please help me to solve this problem.

Thanks





Public Function get_cjena_imp(p_vccid As Integer, p_datum As Date)

Dim RST As Recordset

Dim db As Database

Dim strSQL As String



If Not IsNull(p_vccid) And Not IsNull(p_datum) Then

Set db = CurrentDb

'strSQL = "SELECT P.CIJENA_IMPULSA FROM CRM_BIL_PARAMETRI AS P WHERE
P.VCC_ID= " & CStr(p_vccid) & " AND P.DATUM_OD=(SELECT MAX(P1.DATUM_OD) FROM
CRM_BIL_PARAMETRI P1 WHERE P1.VCC_ID = P.VCC_ID AND P1.DATUM_OD < " &
"cdate('" & CStr(p_datum) & "'));"

strSQL = "SELECT * FROM CRM_BIL_PARAMETRI"

'strSQL = "select * from stat"

-->> Set RST = db.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)

If RST.EOF And RST.BOF Then

Exit Function

End If



get_cjena_imp = RST![CIJENA_IMPULSA]

'db.Properties!AppTitle = "KASA - OPERATER: " & RST![Prezime]

'Application.RefreshTitleBar

RST.Close

Set db = Nothing

'PASS_OK = True

DoCmd.Close

Else

MsgBox "Funkcija get_cjena_imp: jedan od parametara je prazan",
vbCritical



End If



End Function
 
Top