By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,603 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,603 IT Pros & Developers. It's quick & easy.

Access 2002: problem in VB function

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Do you have a reference to the DAO library?
Is it before any references to ADO?

I'm guessing that your program thinks RST is an ADO recordset.
You might want to specify:
Dim RST as DAO.Recordset

HTH
- Turtle

"Michael Dekson" <no****@nospam.com> wrote in message
news:bs**********@ariane.blic.net...
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

Nov 12 '05 #2

P: n/a
Make sure you have set a reference to DAO (Tools - References from the VBE
window). And, you should begin disambigulating your variables:

Dim rst As ADODB.Recordset
Dim dbs As DAO.Database

--
Scott McDaniel
CS Computer Software
Visual Basic - Access - Sql Server - ASP
"Michael Dekson" <no****@nospam.com> wrote in message
news:bs**********@ariane.blic.net...
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

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.