Connecting Tech Pros Worldwide Help | Site Map

Access 2002: problem in VB function

  #1  
Old November 12th, 2005, 06:15 PM
Michael Dekson
Guest
 
Posts: 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


  #2  
Old November 12th, 2005, 06:15 PM
MacDermott
Guest
 
Posts: n/a

re: Access 2002: problem in VB function


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" <nospam@nospam.com> wrote in message
news:bseo27$84m$1@ariane.blic.net...[color=blue]
> 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[/color]
WHERE[color=blue]
> P.VCC_ID= " & CStr(p_vccid) & " AND P.DATUM_OD=(SELECT MAX(P1.DATUM_OD)[/color]
FROM[color=blue]
> 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
>
>[/color]


  #3  
Old November 12th, 2005, 06:15 PM
Scott McDaniel
Guest
 
Posts: n/a

re: Access 2002: problem in VB function


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" <nospam@nospam.com> wrote in message
news:bseo27$84m$1@ariane.blic.net...[color=blue]
> 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[/color]
WHERE[color=blue]
> P.VCC_ID= " & CStr(p_vccid) & " AND P.DATUM_OD=(SELECT MAX(P1.DATUM_OD)[/color]
FROM[color=blue]
> 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
>
>[/color]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
FSO equivalent in VB.net Ben answers 13 December 8th, 2006 08:45 PM
Pointer to a Pointer in VB Dave answers 16 November 20th, 2005 05:14 AM
Problem with my chart in MS Access 2002 using a form and VB StBond answers 3 November 13th, 2005 02:04 PM
Error Trapping In Access 2000 Peter Frost answers 6 November 12th, 2005 10:50 PM