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 -
Sub VR2infointoAllDataTable()
-
Dim strSQL As String
-
Dim db As DAO.Database
-
Dim rs1 As DAO.Recordset
-
Dim rs2 As DAO.Recordset
-
Set db = CurrentDb()
-
Set rs1 = db.OpenRecordset("VR2info", dbOpenTable)
-
Set rs2 = db.OpenRecordset("AllDataTable_4", dbOpenTable)
-
Dim VR2 As String
-
Dim VR2number As Integer
-
Dim Xcoordinate As Single
-
Dim Ycoordinate As Single
-
Dim Habitat As String
-
'VR2number = rs1(0).Value
-
'VR2name1 = rs1(0).Value
-
'VR2name2 = rs2(0).Value
-
rs1.MoveFirst
-
Do Until rs1.EOF
-
rs2.MoveFirst
-
Do Until rs2.EOF
-
If AllDataTable_4.[VR2] = VR2info.[VR2] Then
-
strSQL = "INSERT INTO AllDataTable_4 ([VR2Number],[Xcoordinate],[Ycoordinate],[Habitat])SELECT VR2Number,Xcoordinate,Ycoordinate,Habitat FROM" & VR2info & ";"
-
DoCmd.RunSQL strSQL
-
End If
-
DoCmd.SetWarnings True
-
rs2.MoveNext
-
Loop
-
rs1.MoveNext
-
Loop
-
rs1.Close
-
rs2.Close
-
Set rs1 = Nothing
-
Set rs2 = Nothing
-
End Sub
-
2 1222
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 -
Sub VR2infointoAllDataTable()
-
Dim strSQL As String
-
Dim db As DAO.Database
-
Dim rs1 As DAO.Recordset
-
Dim rs2 As DAO.Recordset
-
Set db = CurrentDb()
-
Set rs1 = db.OpenRecordset("VR2info", dbOpenTable)
-
Set rs2 = db.OpenRecordset("AllDataTable_4", dbOpenTable)
-
Dim VR2 As String
-
Dim VR2number As Integer
-
Dim Xcoordinate As Single
-
Dim Ycoordinate As Single
-
Dim Habitat As String
-
'VR2number = rs1(0).Value
-
'VR2name1 = rs1(0).Value
-
'VR2name2 = rs2(0).Value
-
rs1.MoveFirst
-
Do Until rs1.EOF
-
rs2.MoveFirst
-
Do Until rs2.EOF
-
If AllDataTable_4.[VR2] = VR2info.[VR2] Then
-
strSQL = "INSERT INTO AllDataTable_4 ([VR2Number],[Xcoordinate],[Ycoordinate],[Habitat])SELECT VR2Number,Xcoordinate,Ycoordinate,Habitat FROM" & VR2info & ";"
-
DoCmd.RunSQL strSQL
-
End If
-
DoCmd.SetWarnings True
-
rs2.MoveNext
-
Loop
-
rs1.MoveNext
-
Loop
-
rs1.Close
-
rs2.Close
-
Set rs1 = Nothing
-
Set rs2 = Nothing
-
End Sub
-
Hmm, when you want to loop through the recordset, best first to test for finding records and than process the records like: -
Set rs1 = db.OpenRecordset("VR2info", dbOpenTable)
-
if rs1.eof and rs.bof then
-
exit sub 'Or any other "no data" action...
-
endif
-
'here a record is present and no move first is needed
-
While NOT rs1.EOF
-
'here do your thing
-
rs1.move next 'here go to next record
-
Wend
-
set rs1 = nothing
-
For adding rows in the other table you can use: -
rs2.addnew
-
rs2!Field1txt = 'Test12345'
-
rs2!Field2num = 564
-
rs2!Field3Date = #1/1/2008#
-
rs.update
-
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)
Dear Nico,
many thanks for your reply. I am working through it right now.
Juliane
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)
|
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...
|
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'...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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: 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...
| |