473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Variables And Dlookup

98 New Member
Can someone help me with a variable usage? I keep getting an error message in my DLOOKUP line. It doesn't like me using qryDummy. Maybe I haven't assigned it properly. Can I use a variable with dLOOKUP? when I use an actual table everything works fine! thanks for any help!
Oct 30 '06 #1
7 5379
NeoPa
32,556 Recognized Expert Moderator MVP
If you post your code then we can see if we notice anything that needs to be changed.
Oct 30 '06 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
Can someone help me with a variable usage? I keep getting an error message in my DLOOKUP line. It doesn't like me using qryDummy. Maybe I haven't assigned it properly. Can I use a variable with dLOOKUP? when I use an actual table everything works fine! thanks for any help!
If I remember from previous posts qryDummy is a query definition. You cannot use this in a DLookup.
Oct 30 '06 #3
ineedahelp
98 New Member
I am sorry I didn't post the code. The code below actually works. My problem now is that with this code I am trying to lookup values using a variable "symbol". Both qryDummy and rst have 5000- 6000 records. When I run the code below, it only processes 1000 records in 5 minutes. I feel that either the DLOOKUP function is too slow (which doesn't really make sense) or that there is a problem in the code. Whenever I run and CTRL BREAK out, I notice that the line **If IsNull(varRate) Then** is always yellowed out in my debug window. It IS processing records though....any help?


Private Sub cmbCaptureLSData_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varRate As Variant
Dim strSymbol As String
Dim strSQL As String
Dim qdf As DAO.QueryDef
Dim mDate As String
Dim mNewDate As Date
mDate = Left(MyValue, 2) & "/" & Mid(MyValue, 3, 2) & "/" & Right(MyValue, 2)
Debug.Print mDate
mNewDate = CDate(mDate)
strSQL = "SELECT DailyPrice.LocateDate, DailyPrice.Symbol, DailyPrice.MarketPrice " & _
"FROM DailyPrice WHERE (((DailyPrice.LocateDate) = #" & mNewDate & "#)) " & _
"ORDER BY DailyPrice.Symbol;"
Debug.Print strSQL

Set db = CurrentDb()
Set rst = db.OpenRecordset(tblName)
Set qdf = CurrentDb.QueryDefs("qryDummy")
qdf.SQL = strSQL

If rst.BOF And rst.EOF Then
MsgBox "No records to process"
Else

rst.MoveFirst
Do Until rst.EOF
strSymbol = rst!Symbol '** If symbol is field in recordset but use ! **
varRate = DLookup("[MarketPrice]", "qryDummy", "[symbol] = '" & strSymbol & "'")

If IsNull(varRate) Then
rst.Edit
rst!LSRate = 0
rst.Update
Else
rst.Edit
rst!LSRate = varRate
rst.Update
End If

rst.MoveNext
Loop

End If

rst.Close
qdf.Close
Set rst = Nothing
Set db = Nothing
Set qdf = Nothing

End Sub
Nov 1 '06 #4
ineedahelp
98 New Member
I wanted to also add that I have just run this code on a small (50 record) subset and the program ran fine and it took 5 seconds to complete. Am I expecting too much from Access to run 5000 to 6000 records in a shorter time?
Nov 1 '06 #5
ineedahelp
98 New Member
I am sorry to keep adding to my post, but I wanted to mention that I ran a make table off my qryDummy and used the TABLE instead of the QUERY and it ran in 20 seconds. I will of course change my code and MAKE a TABLE now, but I am still curious why the code ran with the query qryDummy but SO MUCH SLOWER! Any thoughts???
Nov 1 '06 #6
NeoPa
32,556 Recognized Expert Moderator MVP
If I remember from previous posts qryDummy is a query definition. You cannot use this in a DLookup.
Although it is true to say that SQL query strings are not supported in the Domain Aggregate functions, defined queries are supported.

domain A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name.
Nov 1 '06 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
OK this makes more sense. I misunderstood your original question. Your problem here is that you are trying to do a Dlookup on a queryDef while its still open. Close it first and then run the Dlookup as follows:

[code]

Private Sub cmbCaptureLSData_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim varRate As Variant
Dim strSymbol As String
Dim strSQL As String
Dim qdf As DAO.QueryDef
Dim mDate As String
Dim mNewDate As Date
mDate = Left(MyValue, 2) & "/" & Mid(MyValue, 3, 2) & "/" & Right(MyValue, 2)
Debug.Print mDate
mNewDate = CDate(mDate)
strSQL = "SELECT DailyPrice.LocateDate, DailyPrice.Symbol, DailyPrice.MarketPrice " & _
"FROM DailyPrice WHERE (((DailyPrice.LocateDate) = #" & mNewDate & "#)) " & _
"ORDER BY DailyPrice.Symbol;"
Debug.Print strSQL

Set db = CurrentDb()
Set rst = db.OpenRecordset(tblName)
Set qdf = CurrentDb.QueryDefs("qryDummy")
qdf.SQL = strSQL

qdf.Close
Set qdf = Nothing

If rst.BOF And rst.EOF Then
MsgBox "No records to process"
Else

rst.MoveFirst
Do Until rst.EOF
strSymbol = rst!Symbol '** If symbol is field in recordset but use ! **
varRate = DLookup("[MarketPrice]", "qryDummy", "[symbol] = '" & strSymbol & "'")

If IsNull(varRate) Then
rst.Edit
rst!LSRate = 0
rst.Update
Else
rst.Edit
rst!LSRate = varRate
rst.Update
End If

rst.MoveNext
Loop

End If

rst.Close
Set rst = Nothing
Set db = Nothing

End Sub

[/quote]
Nov 1 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
4
by: MLH | last post by:
I have tried using DLookUp in this manner... If DLookUp("","tblClients","='2021234567'") Then MsgBox "Found it!" End If I am wondering if that is a misuse of the DLookUp command? Type...
2
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...
8
by: Christine Henderson | last post by:
I have a problem using the above function in the following simplified circumstance: In the lookup table called "Klms Travelled" I have 3 fields, eg: Receiver Name Receiver Suburb ...
12
by: jimfortune | last post by:
I have a question based somewhat on: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/ddde992b84f762bd/152bbc027bf00720?hl=en#152bbc027bf00720 A local table works well...
11
by: MLH | last post by:
DLookup("", "tblPreliminaryVINs", "=Forms!frmVINODO!SerialNum") is giving me a Type Mismatch error. That's confusing to me and I don't know how to circumvent it. The field in...
2
by: Don | last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with Access. I've been creating databases for several years for work with the help of many of you and trial and error. I have...
9
by: | last post by:
In my database I have a 'control table' in which basic info is stored about the application, for instance the application's path and the name of the company that is using it. In all of the...
15
by: rleepac | last post by:
This is a little complicated but I'll do my best to explain. In my db I have a table called L_AgeCorrection which has the following fields: Age, Sex, Frequency, AgeValue This is a table used to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.