Can anyone help me with the code for updating a table of stock symbols with a rate field (LSRate) - number/long - by using dLOOKUP on another database (DAILYPRICE)? I will often get a variable list of symbols that may or may not have a RATE for that day. I need the symbols to stay in the list. I would like to put "NA" , but can leave them blank if necessary. I have made an attempt at the code but know that some of it isn't going to work. Here it is:
Private Sub cmbCaptureLSData_Click()
Dim db As DAO.Database, rst As DAO.Recordset
Dim varRate As Variant
Dim strSymbol As String
Set db = CurrentDb()
Set rst = db.OpenRecordset("LaBranche_102006")
If rst.BOF And rst.EOF Then
MsgBox "No records to process"
Else
rst.MoveFirst
Do Until rst.EOF
strSymbol = rst.symbol ***CAN I DO THIS?****
varRate = DLookup("symbol", "DailyPrice", "symbol = " & strSymbol & "" ***AND DAILYPRICE.DATE = "10/20/06"*****)
****IF THERE IS NO SYMBOL TO MATCH THIS SYMBOL...PUT "na" IN THE FIELD ELSE PUT varRate*****'if there is no value for that day...put "na" in the Rate column...what about it being a number/long field? How can I put "NA" in this field
rst.MoveNext
Loop
End If
End Sub
8 2003 MMcCarthy 14,534
Recognized Expert Moderator MVP -
-
Private Sub cmbCaptureLSData_Click()
-
Dim db As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim varRate As Variant
-
Dim strSymbol As String
-
-
Set db = CurrentDb()
-
Set rst = db.OpenRecordset("LaBranche_102006")
-
-
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("[symbol]", "DailyPrice", "[symbol] = '" & strSymbol & "' AND [DATE] = " & #10/20/06# & ")"
-
-
If IsNull(varRate) Then
-
rst.Edit
-
rst!LSRate=0
-
rst.Update
-
Else
-
rst.Edit
-
rst!LSRate=varRate
-
rst.Update
-
End IF
-
- '***what about it being a number/long field? How can I put "NA" in this field***
-
'You can't I've set it to 0
-
-
rst.MoveNext
-
Loop
-
-
End If
-
-
rst.Close
-
Set rst = Nothing
-
Set db = Nothing
-
-
End Sub
-
-
Your solutions was fantastic! Now that I see the code it makes great sense! My only problem was that when I ran it on a table with 3700 records, it got through 400 records successfully and then the program "stopped responding" and I needed to close out of everything. This happened twice. Any suggestions as to why this happened? DailyPrice is an extremely large table with 200,000 plus records. Maybe I should query only the date I am interested in. Should this make a difference? Thank you again for all your support with my many questions!
I have tried to create a query with only the info I need instead of the 200,000 plus record table...see code below...I only think that I didn't assign or set the query properly. I get an error #3078 ...can't find the input table or query. Any suggestions? thanks!!!
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
Set db = CurrentDb()
Set rst = db.OpenRecordset("LaBranche_102006")
strSQL = "SELECT DailyPrice.LocateDate, DailyPrice.Symbol, DailyPrice.MarketPrice " & _
"FROM DailyPrice WHERE (((DailyPrice.LocateDate) = #10/20/2006#)) " & _
"ORDER BY DailyPrice.Symbol;"
Set qdf = db.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]", "" & strSQL & "", "[symbol] = '" & strSymbol & "' AND [LocateDate] = #10/20/06#")
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
NeoPa 32,557
Recognized Expert Moderator MVP
Not Responding is just Access's way of saying that it's still processing or waiting for results.
It's pretty crappy I know, but if you leave it to continue it will often finish happily.
I have an alphabetical listing of symbols and after 2 minutes it only got through the b's. Should I not create a subset using a query? If so, I am having trouble assigning it properly so that access recognizes it. any suggestions? Thanks!
MMcCarthy 14,534
Recognized Expert Moderator MVP
Have you created a query called qryDummy? If not then this won't work.
Set qdf = db.QueryDefs("qryDummy")
Could you please look at my code in post #4? I did use the qrydef you suggested. I ran this program with an existing table and it worked. It must be something with my variable to assign the query OR could it be possible that a TABLE is required? any help? Thanks!!
MMcCarthy 14,534
Recognized Expert Moderator MVP
Set qdf = db.QueryDefs("qryDummy")
What I mean is that this only works if there is already a query in the database called qryDummy. Just create a query of anything and name it qryDummy.
Then try running your code again. The other way to do this is:
Set qdf = db.CreateQueryDefs("qryDummy", strSQL)
But you would have to delete the query each time.
Could you please look at my code in post #4? I did use the qrydef you suggested. I ran this program with an existing table and it worked. It must be something with my variable to assign the query OR could it be possible that a TABLE is required? any help? Thanks!!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Old Timer |
last post by:
I wish to type in a number in my "Code" field, for instance 1060, I
then wish the number 1060 to trigger an event that will fill in the
next field (township field) For instance, 1060 brings up and...
|
by: cyoung311 |
last post by:
I'm trying to do an automatic update of one table from another through a
form. Basically, when a selection is made for an item, in this case a
particular workshop, I want to get the associated...
|
by: Chris Jackson |
last post by:
I'm a novice Access user and am not sure how to solve the following problem.
Any help with the following would be greatly appreciated!
I have two tables with identical structures, the first holds...
|
by: Zachary Turner |
last post by:
I want to make a Lookup Field based on another Lookup field. In other
words, I have this table A with two fields: ID and Name, where ID is
an Autonumber and Name is a friendly name. Then I have a...
|
by: Chippy |
last post by:
I am having trouble working out how to update a field on an open form
with a calculation based upon calculations from other tables!
For example, I have 3 tables:
Diary
Diary_ID: autonum,...
| |
by: accessdummy |
last post by:
Hi I have a simple problem that i have no clue in how to solve. I created a new DB with these tables (Department, Users, Ticket). Table department only has the department field i.e. admin, billing,...
|
by: bill |
last post by:
In an application I am writing the user can define a series of
steps to be followed. I save them in a sql database using the
field "order" (a smallint) as the primary key.
(there are in the range...
|
by: samdev |
last post by:
I have set up a table with a few fields that are set to
required....all work fine except the fields that are Lookup from
another table.
What am I forgetting to set?
Thanks!!
|
by: Vinnie the Rat |
last post by:
I need to provide a pick list for a data entry field. I do everything but
take the selected value and get it into the dataset for eventual update to
the the database. I can show the field of the...
|
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: 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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |