473,395 Members | 1,516 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,395 software developers and data experts.

How to fill a field in a subform using a field in the parent form as a lookup?

sueb
379 256MB
I have a form/subform arrangement where the parent form has a Patient_Type that I want to translate into a Hospital_Category based on an existing lookup table. The relationship between Patient_Type and Hospital Category is many-to-one; i.e., there are several patient types that collapse into a single hospital category.

The parent form is "FBR220V direct form" (this is a tab-delimited file supplied to us that we import into an existing table structure). The Patient_Type field's control is "PAT_TYP".

The subform's control is "Coders' Comments". The Hospital_Category field's control is "HospitalCategory".

The lookup table, "Patient Types / Categories", has three fields: "Index" (an autonumber), "Patient Type", and "Hospital Category".

On the subform, the "first" field is the user's initials, which would be the first thing they enter, and I'm thinking that I would like the Hospital Category to be filled only after they supply their initials. So I think I want whatever I do to be in the AfterUpdate property, but I don't know the syntax for using the parent's "PAT_TYPE" as a key to extract "Hospital Category" from the lookup table.

Thanks for your help!
Mar 1 '11 #1
21 4450
TheSmileyCoder
2,322 Expert Mod 2GB
Assuming Patient type is string:

In the afterUpdate event:
Expand|Select|Wrap|Line Numbers
  1. dim strPatType as string
  2. strPatType=Me.Parent.PAT_TYP
  3. Me.HospitalCategory=Dlookup("Hospital Category","[Patient Types / Categories]","PAT_TYPE='" & strpatType & "'")
Mar 1 '11 #2
NeoPa
32,556 Expert Mod 16PB
Another, possibly less obvious, solution is to use a prepopulated, multi-column, ComboBox control where the user can select from the available Patient Types, but what is saved is the column containing the Hospital Category. This avoids repeated lookups in the data and uses a prepopulated list (so table only accessed once) that ensures only valid options are selected.
Mar 1 '11 #3
sueb
379 256MB
I like both these suggestions, and will probably try each in turn, just to see what happens.

NeoPa, is there a way that I could make what you suggest happen programmatically? The imported data provides the Patient_Type, and I think it would be nice and smooth if the subform just filled in the HospitalCategory field (based on the Patient_Type in the parent form) as soon as the user fills in her initials.

(Did I explain that the user is entering data only into the parent form? All the fields on the parent form are locked. If this makes anything clearer, or makes any difference.)
Mar 1 '11 #4
sueb
379 256MB
@TheSmileyCoder: I added the code you suggested to the AfterUpdate event of the field that accepts the coder's initials, but I get run-time error # 3075"Syntax error (missing operator) in query expression 'Hospital Category'." on line 6 (I assume that, for our purposes here, "line 6" is no different from "line 4"--it's just the end of the statement):

Expand|Select|Wrap|Line Numbers
  1. Private Sub Coder_AfterUpdate()
  2.     Dim strPatType As String
  3.     strPatType = Me.Parent.PAT_TYPE
  4.     Me.HospitalCategory = DLookup("Hospital Category", _
  5.                                   "[Patient Types / Categories]", _
  6.                                   "PAT_TYPE='" & strPatType & "'")
  7. End Sub
  8.  
I don't have a very clear understanding of exactly what's happening on that line (which bits are pointing to what), so I'm a little at a loss to know how to fix it.
Mar 1 '11 #5
sueb
379 256MB
@NeoPa: I also want to put buttons on the parent form that would filter the parent records by the Hospital Category of the PAT_TYPE in the parent record.

I'm thinking that, once I get the lookup SQL statement correct, I would put that same statement behind buttons on the parent form. I would like there to be a separate button for each Hospital Category. What do you think?
Mar 1 '11 #6
NeoPa
32,556 Expert Mod 16PB
I'm a bit lost ATM Sue. I don't see how the subform links to the main form, and I don't see any correlation between the user and the PatientType. Without these I don't see how the question even works I'm afraid. I gave general advice that should help without even any understanding of your structure, but to answer your latest comment I'd need an understanding of what's what.

PS. If there's something in the database I've downloaded that might make it clearer you can explain it that way if you prefer.
Mar 1 '11 #7
sueb
379 256MB
I guess I didn't really make very clear what's going on with this data.

The users are provided each day with data from another system. Within this data is the PAT_TYPE field. Each day's data is intended to "overwrite" the previous day's, except that part of what they do with this data requires that they store some processing comments about each record. Currently, they have this horrific manual process involving importing the foreign data into an Excel spreadsheet, and manually copying the previous day's work, matching it up with the new records.

They divide the work (which is relatively massive, 6-7k records each day) among themselves using HospitalCategory, and each hospital category comprises several patient types. Currently, they manually manipulate that gigantic spreadsheet and copy-and-paste the different category sections into different spreadsheets, which they deal out to the right worker.

What I'm trying to set up is two linked tables: one that contains each day's imported data (FBR220V direct import), and another (Coder's Comments) that allows them to store their work. These tables are joined by the unique field PAT_ACCT_NBR. The form I'm working on displays the table containing the imported foreign data (those fields are all locked), and a subform that allows them to store their work.

I've actually changed my mind a little from my original question: I realized that I don't want to store the hospital category, because I was also planning to put some buttons on the parent form that would filter the parent records by HospitalCategory using PAT_TYPE, so if I can just get some help creating those filters (there would be a separate button for each HospitalCategory), I think I'll be cool. (Please note that the attached subform still has the field HospitalCategory, but I'm going to remove that, so please ignore it.)

The lookup table is named Patient Types / Categories.

I hope this makes it a little clearer. If not, here's a scrubbed and decimated database. (The daily table has between 6-7k records in it; this one has a little over 200.) The form that comes up when you open it is the one that I'm working on.

I appreciate any advice; I really want to get them something to ease their pain! :)
Attached Files
File Type: zip BillHold for upload.zip (1.99 MB, 126 views)
Mar 4 '11 #8
NeoPa
32,556 Expert Mod 16PB
Very little clearer I'm afraid Sue, even with the database to hand.

However, if your requirement is simply about how to implement some sort of filtering on either your form or your subform, then I think I can help you if you make what you want clear. I have a copy of the database now, so it should be a little easier to specify I would hope.
Mar 7 '11 #9
sueb
379 256MB
I'm not sure why I'm having such trouble explaining what they need. Basically, they just need to make notes about accounts they are working on, and be able to retain those notes as the daily set of accounts changes. The filter thing is just the way they divvie up the work--each person takes a different hospital category--so I want to make it easy for them to select a category of records to work on.

I want to automate the filtering function with buttons on the parent form, one for each hospital category. Each button would, using the lookup table, filter the parent records (foreign data) to include only those records whose PAT_TYPE fell into the chosen HospitalCategory.

Does that make sense?
Mar 7 '11 #10
NeoPa
32,556 Expert Mod 16PB
It does Sue. It seems this is a simpler question than I think you realise possibly. If I point you at an article that covers what I suspect you need (Cascaded Form Filtering), you can tell me if that fits the bill :-)
Mar 7 '11 #11
sueb
379 256MB
That is a great article, NeoPa!

However, I guess I still don't understand how to do what I want. I want to pick a HospitalCategory, and filter the records that contain any of the various PAT_TYPE values that translate to that HospitalCategory.

It's like I want to use PAT_TYPE as a pointer into the lookup table, retrieve HospitalCategory, and use that as the filter discriminator.
Mar 7 '11 #12
NeoPa
32,556 Expert Mod 16PB
Let me get this straight (Your last paragraph seemed to contradict the previous one so I'm a bit confused). Is it right that you want to select a HospitalCategory from the main form (I assume an unbound ComboBox control) then, using this HospitalCategory value, filter the records of the form to show only those which have a Pat_Type which is associated with the selected HospitalCategory?

If I'm right then this would probably be because the underlying data of the form doesn't, itself, contain the HospitalCategory field. The most straightforward solution to that would be to amend the underlying data to include the HospitalCategory data, while still maintaining an updatable recordset if that's required.

If that's not correct then it can also be done in the code by setting up a string list of all the associated Pat_Types within the selected HospitalCategory.
Mar 8 '11 #13
sueb
379 256MB
It sounds like maybe I've finally managed to untangle my words enough to make some sense! :) Yes, that's right, that's what I want to do.

And you're absolutely right, the underlying data doesn't have HospitalCategory, and, yes, the most straightforward solution would be to amend the underlying data, but the magnitude of 6-7 thousand new records a day dictates that this be automated, and it seems to me that whether I store the HospitalCategory, or just filter on it, step 1 is to use PAT_TYPE to choose HospitalCategory for each record.

Yes? No?

That's the thing I don't know how to do.

And I really thought that a lookup table would be a much more organized and maintainable approach than just a string list, which I personally find sort of icky. If that's the only way to do it, however, then I guess I'll have to do that.
Mar 8 '11 #14
NeoPa
32,556 Expert Mod 16PB
Now I'm not making myself properly clear. When I suggested amending the underlying data, I meant to say amending the design of the RecordSource providing the underlying data. That is to say to use a query that contains the existing underlying data, but also links it to the lookup table you suggested.

Yes, using a Lookup Table is by far the preferable approach. My solution was suggested as it had the benefit of being easily understood as well as not relying on intimate knowledge of your database (that I don't have).

Does this make more sense?
Mar 8 '11 #15
sueb
379 256MB
Ah, a glimmer in the darkness! :)

Okay, I modified the parent form's query to include the lookup table (which already was in relationship with the foreign data), and I added one (of the ultimate 18) Hospital Category buttons to try setting the filter. Here's the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub VCMC_ER_Button_Click()
  2. On Error GoTo Err_VCMC_ER_Button_Click
  3.  
  4. '    Me.Filter = "[Hospital Category] = 'VCMC ER' "
  5.     Me.Filter = "[PAT_TYPE] = 'PSY' "
  6.     Me.FilterOn = True
  7.  
  8. Exit_VCMC_ER_Button_Click:
  9.     Exit Sub
  10.  
  11. Err_VCMC_ER_Button_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_VCMC_ER_Button_Click
  14.  
  15. End Sub
  16.  
I'm able to filter on the PAT_TYPE, but when I tried filtering on the now-available Hospital Category, a pop-up asked me to provide that value.

I just can not figure out how to address the lookup table! What is the correct syntax?? Why is it not available to my button in the same straightforward way it is available to display on the form?
Mar 8 '11 #16
NeoPa
32,556 Expert Mod 16PB
Is it possibly as simple as the fact that the code commented out refers to [Hospital Category], whereas the OP refers to the field as [Hospital_Category]?

If not, we would probably benefit from dealing only with the correct names of all objects in all circumstances.

PS. You have attached a copy of the database to the thread already. Is what we're discussing already available in that copy? If so, how can I find it?
Mar 8 '11 #17
sueb
379 256MB
Here is the database as it stands, and the code in question is behind the button "VCMC ER" on the form "FBR220V direct import".

I realize I've been all over the map with this dumb problem, so I really appreciate your patience with me on it!
Attached Files
File Type: zip BillHold for upload.zip (2.08 MB, 111 views)
Mar 9 '11 #18
NeoPa
32,556 Expert Mod 16PB
Sue, I'm afraid I came across a few things in here that didn't behave as one would normally expect. If you know any reason why opening the table [Hospital Categories] should give the option to open out the [Coders' Comments] table, then please speak up now. There was no relationship defined to link these tables (I suspect one may have been while you were looking into things earlier on and it was simply never properly deleted, even though it is not fully saved/visible either).

I deleted all the relationships I found as well as Compacted/Repaired the database, but without success. I think you may be in the situation where you need to create a new blank database and start importing the objects across, one by one, until you have a solid database to work with. Don't forget to replicate the various items that are database specific though. Not every change you've made will be associated with importable objects.

I didn't find anything wrong with your code BTW. I think you can put that error down to the database corruption. If you download and open the associated database from the article, you can play with that and see what sort of things do and don't work (If that'll help of course).
Mar 9 '11 #19
NeoPa
32,556 Expert Mod 16PB
I did some extra work to clean up the dependency that I confirmed first was spurious. Unfortunately a whole bunch of other issues then came up (and the form continued to exhibit the same behaviour). At this point I would say recreating the database from scratch and importing any usable objects from the old version (as mentioned in my earlier reply) is your next step. Never good news I know, and maybe someone out there knows more about such things than I do and knows a way to fix this without such a step. It looks pretty corrupted to me though, and Access databases are known to get corrupted from time to time depending on how they're used.
Mar 9 '11 #20
sueb
379 256MB
You're right, NeoPa, that ([Hospital Category] linking to [Coder's Comments]) makes no sense. I'll do as you suggest and start with a clean slate and see what I come up with.

Be back (probably much!) later.
Mar 9 '11 #21
NeoPa
32,556 Expert Mod 16PB
I'd be interested to know if that resolves your issue. I must admit I expect it should.
Mar 10 '11 #22

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

Similar topics

25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
4
by: Gerry Abbott | last post by:
Hi all, A subForm control, txtTotalSubForm contains a total from one of the fields on this subForm . The mainForm contains a combo, myCombo which filters, and updates the details on the subForm. I...
2
by: c.kurutz | last post by:
Hello everyone. I have a problem with looking up pricing. Here is what I have so far: TABLES tblItems: itemid itemdescription itemunit (each, roll, square foot) location1price
7
by: dscarbor | last post by:
I have a simple form with 4 fields, and a subform that retrieves records that are potential matches based on a query. The user will use the ID from the subform record and enter it into one of the...
1
by: ckrows | last post by:
Hi guys, I have a parent form that displays the subform. The subform query has a link back to the original ID. I was having issues keepign them in sync, since every parent may not need a...
1
by: Moish | last post by:
I have a form that does not have any bound fields. I want to open a subform on that form to a specific record based on the value of an unbound field on the main form. Obviously the subform is not...
6
by: solom190 | last post by:
Okay this is the situation I have two forms and they have a 1:M relationship. I don't have enough space screen-wise to do a traditional "drag form to form" to create a subform so what I did was...
1
Jerry Maiapu
by: Jerry Maiapu | last post by:
Hi Please help. How can I delete i single record in a datsheet subform from main form using a delete button on the parent form.? i will be more grateful for your help... jm
2
by: Parmenides | last post by:
I get the "this record has been changed by another user since you started editing it" message when I first make an edit in a subform then click on anything in the parent area. It won't give me the...
0
by: sudhirb | last post by:
Hello I am using MS Access 2003. I have a parent form based on parent table which contains unique ID field( primary key) which i enter first on the parent form. Parent table also contains fields...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
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
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...
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...

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.