I am trying to use the following "Elookup" function on a query that gets 2
parameters from an open form.
?eLookup("[MatEst]", "qryWOLPCMatEst")
Returns the following error.
Too few parameters. Expected 2. 48 eLookup Error 3061
Error 3061
?dLookup("[MatEst]", "qryWOLPCMatEst")
Returns the correct value
Is there anyway to get eLookup to see the form values?
Public Function ELookup(expr As String, domain As String, Optional Criteria,
Optional OrderClause)
On Error GoTo Err_ELookup
'Purpose: Faster and more flexible replacement for DLookup()
'Arguments: Same as DLookup, with additional Order By option.
'Return: Value of the Expr if found, else Null or #Error.
'Author: Allen Browne. ab******@bigpond.net.au
'Examples:
'1. To find the last value, include DESC in the OrderClause, e.g.:
' ELookup("[Surname] & [FirstName]", "tblClient", , "ClientID DESC")
'2. To find the lowest non-null value of a field, use the Criteria,
'e.g.:
' ELookup("ClientID", "tblClient", "Surname Is Not Null" , "Surname")
'Note: Requires a reference to the DAO library.
Dim MyDb As Database
Dim rs As Recordset
Dim SQLStg As String
'Build the SQL string.
SQLStg = "SELECT TOP 1 " & expr & " FROM " & domain
If Not IsMissing(Criteria) Then
SQLStg = SQLStg & " WHERE " & Criteria
End If
If Not IsMissing(OrderClause) Then
SQLStg = SQLStg & " ORDER BY " & OrderClause
End If
SQLStg = SQLStg & ";"
'Lookup the value.
Set MyDb = DBEngine(0)(0)
Set rs = MyDb.OpenRecordset(SQLStg, dbOpenForwardOnly)
If rs.RecordCount = 0 Then
ELookup = Null
Else
ELookup = rs(0)
End If
rs.Close
Exit_ELookup:
Set rs = Nothing
Set MyDb = Nothing
Exit Function
Err_ELookup:
' MsgBox Err.Description, vbExclamation, "ELookup Error " & Err.number
If Err.Number < 0& Or Err.Number > 65535 Then 'Valid range for
CVErr()
ELookup = CVErr(5) 'Out of range.
Else
ELookup = CVErr(Err.Number)
End If
Resume Exit_ELookup
End Function 4 6666
You cannot use a parameter query as input to this function.
You cannot use a parameter query as input to the built-in DLookup() either.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"paii, Ron" <pa**@packairinc.com> wrote in message
news:cJ********************@athenet.net... I am trying to use the following "Elookup" function on a query that gets 2 parameters from an open form.
?eLookup("[MatEst]", "qryWOLPCMatEst")
Returns the following error.
Too few parameters. Expected 2. 48 eLookup Error 3061 Error 3061
?dLookup("[MatEst]", "qryWOLPCMatEst")
Returns the correct value
Is there anyway to get eLookup to see the form values?
Public Function ELookup(expr As String, domain As String, Optional Criteria, Optional OrderClause)
On Error GoTo Err_ELookup 'Purpose: Faster and more flexible replacement for DLookup() 'Arguments: Same as DLookup, with additional Order By option. 'Return: Value of the Expr if found, else Null or #Error. 'Author: Allen Browne. ab******@bigpond.net.au 'Examples: '1. To find the last value, include DESC in the OrderClause, e.g.: ' ELookup("[Surname] & [FirstName]", "tblClient", , "ClientID DESC") '2. To find the lowest non-null value of a field, use the Criteria, 'e.g.: ' ELookup("ClientID", "tblClient", "Surname Is Not Null" , "Surname") 'Note: Requires a reference to the DAO library. Dim MyDb As Database Dim rs As Recordset Dim SQLStg As String
'Build the SQL string. SQLStg = "SELECT TOP 1 " & expr & " FROM " & domain If Not IsMissing(Criteria) Then SQLStg = SQLStg & " WHERE " & Criteria End If If Not IsMissing(OrderClause) Then SQLStg = SQLStg & " ORDER BY " & OrderClause End If SQLStg = SQLStg & ";"
'Lookup the value. Set MyDb = DBEngine(0)(0) Set rs = MyDb.OpenRecordset(SQLStg, dbOpenForwardOnly) If rs.RecordCount = 0 Then ELookup = Null Else ELookup = rs(0) End If rs.Close
Exit_ELookup: Set rs = Nothing Set MyDb = Nothing Exit Function
Err_ELookup: ' MsgBox Err.Description, vbExclamation, "ELookup Error " & Err.number If Err.Number < 0& Or Err.Number > 65535 Then 'Valid range for CVErr() ELookup = CVErr(5) 'Out of range. Else ELookup = CVErr(Err.Number) End If Resume Exit_ELookup
End Function
The query uses
((tblxWO.Item)=[Forms]![frmSystem]![qryP2])
in the WHERE clause. and works with dlookup.
[Forms]![frmSystem]![qryP2] is a unbound text field on an open form.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au... You cannot use a parameter query as input to this function.
You cannot use a parameter query as input to the built-in DLookup()
either. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org.
"paii, Ron" <pa**@packairinc.com> wrote in message news:cJ********************@athenet.net...I am trying to use the following "Elookup" function on a query that gets
2 parameters from an open form.
?eLookup("[MatEst]", "qryWOLPCMatEst")
Returns the following error.
Too few parameters. Expected 2. 48 eLookup Error
3061 Error 3061
?dLookup("[MatEst]", "qryWOLPCMatEst")
Returns the correct value
Is there anyway to get eLookup to see the form values?
Public Function ELookup(expr As String, domain As String, Optional Criteria, Optional OrderClause)
On Error GoTo Err_ELookup 'Purpose: Faster and more flexible replacement for DLookup() 'Arguments: Same as DLookup, with additional Order By option. 'Return: Value of the Expr if found, else Null or #Error. 'Author: Allen Browne. ab******@bigpond.net.au 'Examples: '1. To find the last value, include DESC in the OrderClause, e.g.: ' ELookup("[Surname] & [FirstName]", "tblClient", , "ClientID DESC") '2. To find the lowest non-null value of a field, use the Criteria, 'e.g.: ' ELookup("ClientID", "tblClient", "Surname Is Not Null" ,
"Surname") 'Note: Requires a reference to the DAO library. Dim MyDb As Database Dim rs As Recordset Dim SQLStg As String
'Build the SQL string. SQLStg = "SELECT TOP 1 " & expr & " FROM " & domain If Not IsMissing(Criteria) Then SQLStg = SQLStg & " WHERE " & Criteria End If If Not IsMissing(OrderClause) Then SQLStg = SQLStg & " ORDER BY " & OrderClause End If SQLStg = SQLStg & ";"
'Lookup the value. Set MyDb = DBEngine(0)(0) Set rs = MyDb.OpenRecordset(SQLStg, dbOpenForwardOnly) If rs.RecordCount = 0 Then ELookup = Null Else ELookup = rs(0) End If rs.Close
Exit_ELookup: Set rs = Nothing Set MyDb = Nothing Exit Function
Err_ELookup: ' MsgBox Err.Description, vbExclamation, "ELookup Error " &
Err.number If Err.Number < 0& Or Err.Number > 65535 Then 'Valid range for CVErr() ELookup = CVErr(5) 'Out of range. Else ELookup = CVErr(Err.Number) End If Resume Exit_ELookup
End Function
Okay. DLookup is able to use the Expression Service to resolve that kind of
parameter.
The Expression Service is not available in the context of records opened in
code, so it won't work with ELookup().
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"paii, Ron" <pa**@packairinc.com> wrote in message
news:Q6********************@athenet.net... The query uses
((tblxWO.Item)=[Forms]![frmSystem]![qryP2])
in the WHERE clause. and works with dlookup.
[Forms]![frmSystem]![qryP2] is a unbound text field on an open form.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:41***********************@per-qv1-newsreader-01.iinet.net.au... You cannot use a parameter query as input to this function.
You cannot use a parameter query as input to the built-in DLookup() either. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org.
"paii, Ron" <pa**@packairinc.com> wrote in message news:cJ********************@athenet.net... >I am trying to use the following "Elookup" function on a query that gets 2 > parameters from an open form. > > ?eLookup("[MatEst]", "qryWOLPCMatEst") > > Returns the following error. > > Too few parameters. Expected 2. 48 eLookup Error 3061 > Error 3061 > > ?dLookup("[MatEst]", "qryWOLPCMatEst") > > Returns the correct value > > Is there anyway to get eLookup to see the form values? > > Public Function ELookup(expr As String, domain As String, Optional > Criteria, > Optional OrderClause) > > On Error GoTo Err_ELookup > 'Purpose: Faster and more flexible replacement for DLookup() > 'Arguments: Same as DLookup, with additional Order By option. > 'Return: Value of the Expr if found, else Null or #Error. > 'Author: Allen Browne. ab******@bigpond.net.au > 'Examples: > '1. To find the last value, include DESC in the OrderClause, e.g.: > ' ELookup("[Surname] & [FirstName]", "tblClient", , "ClientID > DESC") > '2. To find the lowest non-null value of a field, use the Criteria, > 'e.g.: > ' ELookup("ClientID", "tblClient", "Surname Is Not Null" , "Surname") > 'Note: Requires a reference to the DAO library. > Dim MyDb As Database > Dim rs As Recordset > Dim SQLStg As String > > 'Build the SQL string. > SQLStg = "SELECT TOP 1 " & expr & " FROM " & domain > If Not IsMissing(Criteria) Then > SQLStg = SQLStg & " WHERE " & Criteria > End If > If Not IsMissing(OrderClause) Then > SQLStg = SQLStg & " ORDER BY " & OrderClause > End If > SQLStg = SQLStg & ";" > > 'Lookup the value. > Set MyDb = DBEngine(0)(0) > Set rs = MyDb.OpenRecordset(SQLStg, dbOpenForwardOnly) > If rs.RecordCount = 0 Then > ELookup = Null > Else > ELookup = rs(0) > End If > rs.Close > > Exit_ELookup: > Set rs = Nothing > Set MyDb = Nothing > Exit Function > > Err_ELookup: > ' MsgBox Err.Description, vbExclamation, "ELookup Error " & Err.number > If Err.Number < 0& Or Err.Number > 65535 Then 'Valid range for > CVErr() > ELookup = CVErr(5) 'Out of range. > Else > ELookup = CVErr(Err.Number) > End If > Resume Exit_ELookup > > End Function
Thank you for your help and the function(s).
By the way I modified the record set open with the following line
Set rs = CurrentDb.OpenRecordset(SQLStg, dbOpenForwardOnly)
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au... Okay. DLookup is able to use the Expression Service to resolve that kind
of parameter.
The Expression Service is not available in the context of records opened
in code, so it won't work with ELookup().
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org.
"paii, Ron" <pa**@packairinc.com> wrote in message news:Q6********************@athenet.net... The query uses
((tblxWO.Item)=[Forms]![frmSystem]![qryP2])
in the WHERE clause. and works with dlookup.
[Forms]![frmSystem]![qryP2] is a unbound text field on an open form.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:41***********************@per-qv1-newsreader-01.iinet.net.au... You cannot use a parameter query as input to this function.
You cannot use a parameter query as input to the built-in DLookup() either. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org.
"paii, Ron" <pa**@packairinc.com> wrote in message news:cJ********************@athenet.net... >I am trying to use the following "Elookup" function on a query that
gets 2 > parameters from an open form. > > ?eLookup("[MatEst]", "qryWOLPCMatEst") > > Returns the following error. > > Too few parameters. Expected 2. 48 eLookup Error 3061 > Error 3061 > > ?dLookup("[MatEst]", "qryWOLPCMatEst") > > Returns the correct value > > Is there anyway to get eLookup to see the form values? > > Public Function ELookup(expr As String, domain As String, Optional > Criteria, > Optional OrderClause) > > On Error GoTo Err_ELookup > 'Purpose: Faster and more flexible replacement for DLookup() > 'Arguments: Same as DLookup, with additional Order By option. > 'Return: Value of the Expr if found, else Null or #Error. > 'Author: Allen Browne. ab******@bigpond.net.au > 'Examples: > '1. To find the last value, include DESC in the OrderClause, e.g.: > ' ELookup("[Surname] & [FirstName]", "tblClient", , "ClientID > DESC") > '2. To find the lowest non-null value of a field, use the
Criteria, > 'e.g.: > ' ELookup("ClientID", "tblClient", "Surname Is Not Null" ,
"Surname") > 'Note: Requires a reference to the DAO library. > Dim MyDb As Database > Dim rs As Recordset > Dim SQLStg As String > > 'Build the SQL string. > SQLStg = "SELECT TOP 1 " & expr & " FROM " & domain > If Not IsMissing(Criteria) Then > SQLStg = SQLStg & " WHERE " & Criteria > End If > If Not IsMissing(OrderClause) Then > SQLStg = SQLStg & " ORDER BY " & OrderClause > End If > SQLStg = SQLStg & ";" > > 'Lookup the value. > Set MyDb = DBEngine(0)(0) > Set rs = MyDb.OpenRecordset(SQLStg, dbOpenForwardOnly) > If rs.RecordCount = 0 Then > ELookup = Null > Else > ELookup = rs(0) > End If > rs.Close > > Exit_ELookup: > Set rs = Nothing > Set MyDb = Nothing > Exit Function > > Err_ELookup: > ' MsgBox Err.Description, vbExclamation, "ELookup Error " & Err.number > If Err.Number < 0& Or Err.Number > 65535 Then 'Valid range for > CVErr() > ELookup = CVErr(5) 'Out of range. > Else > ELookup = CVErr(Err.Number) > End If > Resume Exit_ELookup > > End Function
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
A very strange bug. www.monkeyclaus.org is run by a cms I'm
developing. One of types of users we allow is "justTestingTheSite", a
type of user I developed to give demo's to prospective clients. The...
|
by: Polar |
last post by:
I am having troubles finding the parse error in this script. I've been
checking for weeks. I am too new to the subject I guess.
I am trying to show a readord and them have a form at the bottom...
|
by: jaysonsch |
last post by:
Hello!
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the...
|
by: shank |
last post by:
1) I'm getting this error: Syntax error (missing operator) in query
expression on the below statement. Can I get some advice.
2) I searched ASPFAQ and came up blank. Where can find the "rules"...
|
by: DBNovice |
last post by:
I have a database that keeps records on the issue and failure of an item.
Currently, the database is poorly desisned; therefore I'm performing queries
to break the data into normalized tables and...
|
by: netpurpose |
last post by:
I need to extract data from this table to find the lowest prices of
each product as of today. The product will be listed/grouped by the
name only, discarding the product code - I use...
|
by: P.L. Owens |
last post by:
I am trying to open a pop-up window with its own htm code, in order to show
an enlargement of a thumbnail. But I am passing a query string after the? in
the url of the new window. for example:...
|
by: Harvey |
last post by:
Hi,
I try to write an asp query form that lets client search any text-string and
display all pages in my web server that contain the text. I have IIS 6.0 on a
server 2003. The MSDN site says...
|
by: ctyrrell |
last post by:
I have read with interest the many discussions of the 3048 Error:
Cannot open any more databases. I understand how the number of open
Table ID's causes the problem. My question has to do with the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |