473,503 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating A Field With Lookup

98 New Member
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
Oct 25 '06 #1
8 2003
MMcCarthy
14,534 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmbCaptureLSData_Click()
  3. Dim db As DAO.Database
  4. Dim rst As DAO.Recordset
  5. Dim varRate As Variant
  6. Dim strSymbol As String
  7.  
  8. Set db = CurrentDb()
  9. Set rst = db.OpenRecordset("LaBranche_102006")
  10.  
  11. If rst.BOF And rst.EOF Then
  12.     MsgBox "No records to process"
  13. Else
  14.  
  15. rst.MoveFirst
  16. Do Until rst.EOF
  17. strSymbol = rst!symbol   '** If symbol is field in recordset but use ! **
  18. varRate = DLookup("[symbol]", "DailyPrice", "[symbol] = '" & strSymbol & "' AND [DATE] = " & #10/20/06# & ")"
  19.  
  20. If IsNull(varRate) Then
  21.     rst.Edit
  22.     rst!LSRate=0
  23.     rst.Update
  24. Else
  25.     rst.Edit
  26.     rst!LSRate=varRate
  27.     rst.Update
  28. End IF
  29.  
  30. '***what about it being a number/long field? How can I put "NA" in this field***
  31. 'You can't I've set it to 0
  32.  
  33. rst.MoveNext
  34. Loop
  35.  
  36. End If
  37.  
  38. rst.Close
  39. Set rst = Nothing
  40. Set db = Nothing
  41.  
  42. End Sub
  43.  
  44.  
Oct 26 '06 #2
ineedahelp
98 New Member
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!
Oct 26 '06 #3
ineedahelp
98 New Member
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
Oct 26 '06 #4
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.
Oct 26 '06 #5
ineedahelp
98 New Member
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!
Oct 26 '06 #6
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")
Oct 26 '06 #7
ineedahelp
98 New Member
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!!
Oct 26 '06 #8
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!!
Oct 26 '06 #9

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

Similar topics

1
2568
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...
6
6152
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...
1
1850
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...
1
3341
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...
1
1639
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,...
1
1389
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,...
33
3254
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...
7
2571
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!!
2
1241
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...
0
7202
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
7280
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
7330
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
7460
tracyyun
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...
0
5578
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,...
0
4672
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
3167
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...
0
1512
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 ...
0
380
bsmnconsultancy
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...

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.