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? - Private Sub sFindNullFields()
-
'This subroutine finds all READ records and counts both the number
-
'of fields in total, along with the number of null fields
-
Dim tdf As DAO.TableDef
-
Dim Dba As Database
-
Dim Rst As Recordset
-
Dim RstIgnore As Recordset
-
Dim i As Integer
-
Dim lIgnoreHospitalNumber(25) As Long
-
Dim lRecordCount As Long
-
Dim lTotalFields As Long
-
Dim lNullFields As Long
-
i = 0
-
-
'First need to identify which records to ignore as patient not yet discharged
-
'To do this, identify recs and populate array for use later
-
Set Dba = CurrentDb
-
Set RstIgnore = Dba.OpenRecordset("SELECT DateLeftHospital, HospitalNumber FROM READ_SummaryData WHERE DateLeftHospital Is Null", dbReadOnly)
-
With RstIgnore
-
Do Until .EOF = True
-
lIgnoreHospitalNumber(i) = !HospitalNumber
-
i = i + 1
-
.MoveNext
-
Loop
-
End With
-
-
'Now need to loop through tables starting with 'READ' and
-
'count ALL fields along with all NULL fields
-
'but excluding all records containing 'Ignore' the hospital number
-
For Each tdf In Dba.TableDefs
-
If Left(tdf.Name, 4) = "READ" Then
-
Set Rst = Dba.OpenRecordset(tdf.Name, dbReadOnly)
-
With Rst
-
Do Until .EOF = True
-
lTotalFields = lTotalFields + Rst.Fields.Count 'Want total fields for all records in each table
-
'Now want to loop through all fields in each record to count any null values
-
For i = 0 To .Fields.Count - 1
-
If .Fields(i).Value = False Then
-
lNullFields = lNullFields + 1
-
End If
-
Next i
-
.MoveNext
-
Loop
-
End With
-
End If
-
Next
-
MsgBox "Percent Null: " & Format(lNullFields / lTotalFields, "Percent"), 64, "Finished..."
-
End Sub
-
-
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.
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.
Wouldn't that be
With RecSetx
.... .fields(0) ' would be the field you want
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.
Thanks RecSetx, that was what I wanted. I think its called the ordinal reference. Thank you.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,...
|
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
|
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...
|
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 =...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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
|
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...
| |