473,566 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hit a snag looping through tables and records

21 New Member
I am producing a statistic for one of the managers at work concerning hospital patients. I have a database with about 120 tables, some of which relate to a set of patients. All the table names I am interested in start with the four letters 'READ'. I loop through each of these tables, then loop through each record, and finally loop through each field. I am counting the total number of fields, and the total number of null fields. This all works fine.

Problem is, there are certain records I need to ignore because the patient has not been discharged. I first identify the unique patient hospital number and save this to an array, and was then planning to use this to identify any such record in any of the tables.

The problem I have is that the field in each separate table holding the hospital number does not have the same field name in every case, so I can't refer to a name. I remember reading somewhere it is possible to refer to a field by its number, such as 1 being the first field, 2 the second and so on. In every case, the first field holds the hospital number, in data type Number. Does anyone know is this true, and how can I include it in the code below, which excludes any attempt at ignoring records?

Expand|Select|Wrap|Line Numbers
  1. Private Sub sFindNullFields()
  2. 'This subroutine finds all READ records and counts both the number
  3. 'of fields in total, along with the number of null fields
  4. Dim tdf As DAO.TableDef
  5. Dim Dba As Database
  6. Dim Rst As Recordset
  7. Dim RstIgnore As Recordset
  8. Dim i As Integer
  9. Dim lIgnoreHospitalNumber(25) As Long
  10. Dim lRecordCount As Long
  11. Dim lTotalFields As Long
  12. Dim lNullFields As Long
  13. i = 0
  14.  
  15. 'First need to identify which records to ignore as patient not yet discharged
  16. 'To do this, identify recs and populate array for use later
  17. Set Dba = CurrentDb
  18. Set RstIgnore = Dba.OpenRecordset("SELECT DateLeftHospital, HospitalNumber FROM READ_SummaryData WHERE DateLeftHospital Is Null", dbReadOnly)
  19. With RstIgnore
  20.     Do Until .EOF = True
  21.         lIgnoreHospitalNumber(i) = !HospitalNumber
  22.         i = i + 1
  23.         .MoveNext
  24.     Loop
  25. End With
  26.  
  27. 'Now need to loop through tables starting with 'READ' and
  28. 'count ALL fields along with all NULL fields
  29. 'but excluding all records containing 'Ignore' the hospital number
  30. For Each tdf In Dba.TableDefs
  31.     If Left(tdf.Name, 4) = "READ" Then
  32.         Set Rst = Dba.OpenRecordset(tdf.Name, dbReadOnly)
  33.         With Rst
  34.             Do Until .EOF = True
  35.                 lTotalFields = lTotalFields + Rst.Fields.Count 'Want total fields for all records in each table
  36.                 'Now want to loop through all fields in each record to count any null values
  37.                 For i = 0 To .Fields.Count - 1
  38.                     If .Fields(i).Value = False Then
  39.                         lNullFields = lNullFields + 1
  40.                     End If
  41.                 Next i
  42.                 .MoveNext
  43.             Loop
  44.         End With
  45.     End If
  46. Next
  47. MsgBox "Percent Null: " & Format(lNullFields / lTotalFields, "Percent"), 64, "Finished..."
  48. End Sub
  49.  
  50.  
Mar 1 '11 #1
5 1892
Rabbit
12,516 Recognized Expert Moderator MVP
I'm not sure what your question is because you say that you want to refer to the field by it's position in the recordset but you're already doing that in your code.
Mar 2 '11 #2
bigukfan
21 New Member
What I mean is that in all recordsets the first field is the hospital number, but how can i refer to the first field if not by name? Thanks for looking at this for me.
Mar 2 '11 #3
orangeCat
83 New Member
Wouldn't that be

With RecSetx
.... .fields(0) ' would be the field you want
Mar 2 '11 #4
Rabbit
12,516 Recognized Expert Moderator MVP
What I'm trying to tell you is that you are already referencing fields by their position in the very code you posted.
Mar 2 '11 #5
bigukfan
21 New Member
Thanks RecSetx, that was what I wanted. I think its called the ordinal reference. Thank you.
Mar 2 '11 #6

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

Similar topics

4
4073
by: Roy Adams | last post by:
Hi posting again because no answer to previous.. tring to loop through a recordset and update a record, thing is it only updates the first record in the table rather than searching through the entire table or records returned, and updating a record if certain criteria is met. shouldn't the while loop do this? I know my syntax must be wrong,...
6
17972
by: Michael Goerz | last post by:
Hi, I'm trying to write a loop that cycles through all the records. This I use for doing comparisons between all records or to export all records to a text file. I'm using the following code: '************************************* .... 'Finding the count of all records
8
2086
by: RC | last post by:
I have a table that lists many box numbers. Each box number has a Pallet Number (indicating which pallet the box is in). When the Pallets are loaded into a shipping Container I need to update the table to indicate which pallets and boxes are in the container. In my code below, in the table named "Products", I find the first Pallet Number...
6
4627
by: RC | last post by:
My code below will loop through all the records in the table, and when the if statement is true it goes to the ***Me.ContainerNumberProductsTable = GETContainerNumber.Value*** bit like should but it does not make the change/update in the table. Any ideas? Dim rst As Object Set rst = Me.Recordset.Clone If Not rst.EOF Then Me.Bookmark =...
20
3043
by: Stewart Graefner | last post by:
Here is a chunk of code that works for an individual record. It evaluates dates and checks or unchecks boxes as it goes along. It may not be pretty but it works. What my problem is that I need it to evaluate all the records(200+) in my db and change those which need changing. Having to do it individually would defeat the purpose of developing...
1
9078
by: BB | last post by:
I want to be able to load a table into a dataset in my VB.NET app, check each field/column of each row/record for missing or incorrect data, then update a field/column in the record to indicate an error was found. Eventually, I'll want to save that table data back to the database. Does anyone have any sample code I can look at for...
3
1889
by: David | last post by:
Hi, I have an asp page which lists records out in rows Each record has a checkbox with a value parameter equal to the RecordID When the form is run, it goes to a page which I am trying to create 1 report printed after the other. i.e. if the user selects 3 records on the form, the report is printed on the next asp page for record 1 and...
6
2724
by: mahowe | last post by:
Hi, I have had this problem for a while and have not been able solve it. What im looking at doing is looping thru my patient table and trying to organise the patients in to there admission sequence, so when patient "A" comes in and is treated at my hospital and is discharged and admitted to another Hospital within one day then patient "A" will...
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
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 we have to send another system
0
926
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.