Function Problem

G

Guest

Would you please tell me the problem of the following function?
Public Function GetOrderQtyIssue(StockPN As String) As Long
Dim Stemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Stemp = "Select Top 1 [Current_Purchasing_Order1].OrderQty From
[Current_Purchasing_Order1] Where
((([Current_Purchasing_Order1].PN)=[StockPN])) Order By
[Current_Purchasing_order1].IssueDate"
Rs.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
GetOrderQtyIssue = 0
If Not Rs.EOF Then
GetOrderQtyIssue = Nz(Rs("OrderQty"), 0)
Rs.Close
End If
Rs.Close
Set Rs = Nothing
End Function
 
G

Guest

What is the error? if there is any.
Also the StockPN parameter need to be taken out of the string of the SQL.
putting it in square brakets wont help for the SQL to recognize it


Stemp = "Select Top 1 [Current_Purchasing_Order1].OrderQty From
[Current_Purchasing_Order1] Where
((([Current_Purchasing_Order1].PN)='" & StockPN & "')) Order By
[Current_Purchasing_order1].IssueDate"
 
G

Guest

I have revised the function like your instruction. But when I used this
function in a query, it shows: "GetOrderQtyIssue has no definition"
Would you please tell me what is wrong with this function?

Thanks

Shell

Ofer Cohen said:
What is the error? if there is any.
Also the StockPN parameter need to be taken out of the string of the SQL.
putting it in square brakets wont help for the SQL to recognize it


Stemp = "Select Top 1 [Current_Purchasing_Order1].OrderQty From
[Current_Purchasing_Order1] Where
((([Current_Purchasing_Order1].PN)='" & StockPN & "')) Order By
[Current_Purchasing_order1].IssueDate"

--
Good Luck
BS"D


Shell said:
Would you please tell me the problem of the following function?
Public Function GetOrderQtyIssue(StockPN As String) As Long
Dim Stemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Stemp = "Select Top 1 [Current_Purchasing_Order1].OrderQty From
[Current_Purchasing_Order1] Where
((([Current_Purchasing_Order1].PN)=[StockPN])) Order By
[Current_Purchasing_order1].IssueDate"
Rs.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
GetOrderQtyIssue = 0
If Not Rs.EOF Then
GetOrderQtyIssue = Nz(Rs("OrderQty"), 0)
Rs.Close
End If
Rs.Close
Set Rs = Nothing
End Function
 
S

SONIA C S

Shell said:
Would you please tell me the problem of the following function?
Public Function GetOrderQtyIssue(StockPN As String) As Long
Dim Stemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Stemp = "Select Top 1 [Current_Purchasing_Order1].OrderQty From
[Current_Purchasing_Order1] Where
((([Current_Purchasing_Order1].PN)=[StockPN])) Order By
[Current_Purchasing_order1].IssueDate"
Rs.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
GetOrderQtyIssue = 0
If Not Rs.EOF Then
GetOrderQtyIssue = Nz(Rs("OrderQty"), 0)
Rs.Close
End If
Rs.Close
Set Rs = Nothing
End Function
 
S

Stefan Hoffmann

hi,
I have revised the function like your instruction. But when I used this
function in a query, it shows: "GetOrderQtyIssue has no definition"
Would you please tell me what is wrong with this function?
Your function must reside in a normal module. The modul must have a
differnt name than your function. The two first lines in your module
should be

Option Compare Database
Option Explicit

Compile your database (Menue Debug/Compile).


mfG
--> stefan <--
 
G

Guest

Well done!
Thanks a lot
Shell

Stefan Hoffmann said:
hi,

Your function must reside in a normal module. The modul must have a
differnt name than your function. The two first lines in your module
should be

Option Compare Database
Option Explicit

Compile your database (Menue Debug/Compile).


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Question in Access Recordset 3
ADO Recordset 4
Update ADODB Recordset 1
NZ function? 6
ADO Connect string 3
How do I get every fifth record to print? 4
Error 3061 1
Data Access Page help needed 5

Top