473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Adding info to a table from another table

Dear all,

In this code I am trying to loop through two tables AllDatatable_4 and VR2info, adding GIS coordinates that are associated with sample loactions called VR2 to AllDatatable_4. I am a newcomer to access and have been pulling my hair out over this problem. The code compiles but gives an error message "object required". I believe that I am not looping correctly though the two tables. Is there somebody more experienced who could help ?

Many thanks,

Juliane
Expand|Select|Wrap|Line Numbers
  1. Sub VR2infointoAllDataTable()
  2. Dim strSQL As String
  3. Dim db As DAO.Database
  4. Dim rs1 As DAO.Recordset
  5. Dim rs2 As DAO.Recordset
  6. Set db = CurrentDb()
  7. Set rs1 = db.OpenRecordset("VR2info", dbOpenTable)
  8. Set rs2 = db.OpenRecordset("AllDataTable_4", dbOpenTable)
  9. Dim VR2 As String
  10. Dim VR2number As Integer
  11. Dim Xcoordinate As Single
  12. Dim Ycoordinate As Single
  13. Dim Habitat As String
  14. 'VR2number = rs1(0).Value
  15. 'VR2name1 = rs1(0).Value
  16. 'VR2name2 = rs2(0).Value
  17. rs1.MoveFirst
  18. Do Until rs1.EOF
  19.   rs2.MoveFirst
  20.   Do Until rs2.EOF
  21.    If AllDataTable_4.[VR2] = VR2info.[VR2] Then
  22.    strSQL = "INSERT INTO AllDataTable_4 ([VR2Number],[Xcoordinate],[Ycoordinate],[Habitat])SELECT VR2Number,Xcoordinate,Ycoordinate,Habitat FROM" & VR2info & ";"
  23.    DoCmd.RunSQL strSQL
  24.    End If
  25.    DoCmd.SetWarnings True
  26.   rs2.MoveNext
  27.   Loop
  28. rs1.MoveNext
  29. Loop
  30. rs1.Close
  31. rs2.Close
  32. Set rs1 = Nothing
  33. Set rs2 = Nothing
  34. End Sub
  35.  
Dec 27 '07 #1
2 1222
nico5038
3,080 Expert 2GB
Dear all,

In this code I am trying to loop through two tables AllDatatable_4 and VR2info, adding GIS coordinates that are associated with sample loactions called VR2 to AllDatatable_4. I am a newcomer to access and have been pulling my hair out over this problem. The code compiles but gives an error message "object required". I believe that I am not looping correctly though the two tables. Is there somebody more experienced who could help ?

Many thanks,

Juliane
Expand|Select|Wrap|Line Numbers
  1. Sub VR2infointoAllDataTable()
  2. Dim strSQL As String
  3. Dim db As DAO.Database
  4. Dim rs1 As DAO.Recordset
  5. Dim rs2 As DAO.Recordset
  6. Set db = CurrentDb()
  7. Set rs1 = db.OpenRecordset("VR2info", dbOpenTable)
  8. Set rs2 = db.OpenRecordset("AllDataTable_4", dbOpenTable)
  9. Dim VR2 As String
  10. Dim VR2number As Integer
  11. Dim Xcoordinate As Single
  12. Dim Ycoordinate As Single
  13. Dim Habitat As String
  14. 'VR2number = rs1(0).Value
  15. 'VR2name1 = rs1(0).Value
  16. 'VR2name2 = rs2(0).Value
  17. rs1.MoveFirst
  18. Do Until rs1.EOF
  19.   rs2.MoveFirst
  20.   Do Until rs2.EOF
  21.    If AllDataTable_4.[VR2] = VR2info.[VR2] Then
  22.    strSQL = "INSERT INTO AllDataTable_4 ([VR2Number],[Xcoordinate],[Ycoordinate],[Habitat])SELECT VR2Number,Xcoordinate,Ycoordinate,Habitat FROM" & VR2info & ";"
  23.    DoCmd.RunSQL strSQL
  24.    End If
  25.    DoCmd.SetWarnings True
  26.   rs2.MoveNext
  27.   Loop
  28. rs1.MoveNext
  29. Loop
  30. rs1.Close
  31. rs2.Close
  32. Set rs1 = Nothing
  33. Set rs2 = Nothing
  34. End Sub
  35.  
Hmm, when you want to loop through the recordset, best first to test for finding records and than process the records like:
Expand|Select|Wrap|Line Numbers
  1. Set rs1 = db.OpenRecordset("VR2info", dbOpenTable)
  2. if rs1.eof and rs.bof then
  3.      exit sub 'Or any other "no data" action...
  4. endif
  5. 'here a record is present and no move first is needed
  6. While NOT rs1.EOF
  7.    'here do your thing
  8.    rs1.move next 'here go to next record
  9. Wend
  10. set rs1 = nothing
  11.  
For adding rows in the other table you can use:
Expand|Select|Wrap|Line Numbers
  1.    rs2.addnew
  2.    rs2!Field1txt = 'Test12345'
  3.    rs2!Field2num = 564
  4.    rs2!Field3Date = #1/1/2008#
  5.    rs.update
  6.  
As you can see, using rs2! will allow the use of the fieldnames of the recordset, for rs1 the same can be applied. The (0) you use would need: rs1.fields(0) to get a value available, but I prefer fieldnames :-)

Clearer ?

Nic;o)
Dec 28 '07 #2
Dear Nico,

many thanks for your reply. I am working through it right now.

Juliane
Jan 6 '08 #3

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

Similar topics

1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
2
by: Niels Jensen | last post by:
I have the following code in a Sub which is called by a do loop statement for each line starting with unit info in an e-mail based game that I play. I'm exctracting the keywords from the text and...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
1
by: Mr. B | last post by:
VB.net 2003 c/w Framework 1.1 and MS Access db We have a commercial program that does our Acounting and Time Sheets (Timberline). At least once a day our Accounting department runs a Script...
3
by: corear | last post by:
I have a new case tracking system. The cases table has these fields: CaseID (Primary Key) StatusID (looked up in another table - Open, Pending, or Closed) Status Comment (memo field) Date&Time...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
5
by: GarryJones | last post by:
I have code numbers in 2 fields from a table which correspond to month and date. (Month, Code number) Field name = ml_mna 1 2 3 etc up to 12 (Data is entered without a leading zero)
2
by: dympna | last post by:
Hi can anyone suggest a fix for this... as I am a novice in access. I have created a training table with the following fields Employee Name - joe Training Received - Fork lift Date Received...
10
by: thebuzzman | last post by:
I am creating a database for inputing ambulance run sheets. I have a table that lists different history conditions (HTN, CHF, Asthma....) In my main report form, I have a combo box that gets its'...
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
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
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
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
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...

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.