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!
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.
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.
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
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?
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???
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.
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]
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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: 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 ...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |