Connecting Tech Pros Worldwide Help | Site Map

Access 2002: problem in VB function

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 05:15 PM
Michael Dekson
Guest
 
Posts: n/a
Default Access 2002: problem in VB function

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, 05:15 PM
MacDermott
Guest
 
Posts: n/a
Default 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, 05:15 PM
Scott McDaniel
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.