1 form, 2 tables

J

JoJo

I have been using a functional, albeit somewhat cumbersome, Access database
that I developed with almost zippo previous knowledge of Access (hence the
cumbersome but functional part). I decided that I’m tired of “cumbersome.â€
I’ve seen threads that address part of my issue; I suspect someone’s going to
tell me I’m doing things all wrong, but I’m leery of doing a major rewire.
However, since my complaint is not about storage but about viewing data,
well, here goes.


I’m working in Access 2003. Basically, I have 2 tables: Patients and TestA
(also have B thru J, but if I can get A to work, the rest are the same).

Patients table has 3 columns: PtID (PKey), FirstName, LastName

TestA has 10 columns: APtID (PKey), AResult1, AResult2, AResult3, etc.
through AResult9.

Patients table is relatively static—patient names and ID numbers have been
entered already. The two tables have a 1-to-1 relationship based on PtID.

TestA table contains results of Test A for patients who have completed that
test. Those results have been entered via a form, also designated TestA.
Data capture/storage is fine. My issue is with the form, specifically
viewing of FirstName and LastName as identification confirmation. Yes, I’ve
seen this issue on several threads on this site.

OK, so I wanted my form to reflect everything in the TestA table (which it
does) PLUS the patient first and last name from the Patients table. As I’ve
seen on this site, one easy way to do that is a DLookup. However, Access
2003 also lets you base a form on multiple tables, which displays like
DLookup, but is even easier(but probably just as evil, developmentally?) to
set up, including concatenating the names. Seriously, no query, no subform,
no mess, no fuss.

That, in a nutshell, is the basis for every question to follow.

What I want is to be able to 1) go to a new record on the form, 2) enter a
PtID in the control box on the form (control source is the PtID from the
TestA table), and 3) have Access pull the patient’s name from the Patients
table into the control on the form whose control source is the concatenated
FirstName and LastName from the Patients table. I’m not trying to plug that
info into the TestA table—just want to SEE it on the form.

Then I want to 4) be able to enter data on the rest of the screen. Here’s
what I’m doing now; it’s working, but inefficiently cumbersome.

I enter the PtID in that box on the form. Then I click on the control box
where the Names should appear. What I have discovered is that just because I
told Access I want the Patients table to cough up the associated patient name
value for that PtID, it doesn’t mean that it will. One apparently has to pat
Access’ back to get it to cough, and apparently one way to do that is the
Action called Requery.

So I set up a macro to Requery when I clicked on the name control box. That
pulls the names from Patient alright, but I only see it blink, and then
Access immediately kicks me to the beginning of the record set where, yikes,
if I don’t realize where I am and start typing, I can overwrite existing data
by touching just about any key.

OK, so what I would like from the point of Requery is a way to keep myself
on that new record. That is eluding me. The best I’ve been able to do is to
add an Action to the macro, GoToRecord, which gives me the choice of getting
kicked to a brand-new record, where at least I can’t damage anything already
in there. Then I have to manually scroll my way through the record set to
the new record, which shows the PtID, has the name nice and updated, and has
the rest of the form all pretty and blank and ready to capture data. That’s
a royal pain (I mean, after all, isn’t a computer supposed to do everything
for you?!), and it lays open the later possibility that somebody who is not
as invested in all of this as I am is going to goof something up big time.
(Note: I’m the only user for now.)

My workaround, now that I have a hundred patients to scroll through, was to
rob (I’m an SQL dummy) some code from an old database in our system that had
a Search button. So now I can hit a Search button on my form, enter the
PtID, and go right to the record I want. Functional but stupid.

I would even be happy if I could hit the End arrow at the bottom of the
Access screen and jump to what should be the last record—i.e., the one I just
entered. However, my tables and form records seem INSISTENT on sorting on
that primary key, basically PtID, as opposed to natural order (in the order
entered, right?). While ascending PtID makes sense when scrolling through
records, efficiency dictates that I not do too much scrolling . I think I
have tried everything “the book†says to clear out existing sort orders, but
to no avail. I can’t get a table or a form to revert to order entered (maybe
it doesn’t ever go back?) or to go by order entered from this point forward.
If I solved this sorting issue, ALL of the above would go away, because I
could set the GoToRecord line on the macro to Last, and boom, in one click,
at the end of the dataset would be my new entry—i.e., the last one added.

The bottom line is, I want a form to pull a LITTLE information from a
different table than it’s writing to—and not throw me all over the data set.
Are my requests and techniques really that ill conceived? Sorry for the
novel...
 
K

Klatuu

2003 does not allow multiple tables used by one form without either a subform
or a query. 2007 has a split form that can, but, As long as a patient has
one and only one occurance of test A and never ever will under any
circumstances have another test A, I still wouldn't do it the way I am going
so suggest, because sooner or later, some patient is going to have to retake
Test A.

You can use a couple of controls on your form with a DLookup in the control
source that will return the first and last time for the patient.
 
J

JoJo

Dave, thanks for a really quick response!

OK, first of all, yes, one patient, one Test A; study done, never see them
again--research project.

Next thing, what I should have said earlier was that early in development I
tried DLookup for the names; this produced virtually the same results. My
beef isn't so much about how to get names to appear (requery did technically
accomplish that) but that I still had to navigate my way back to the new
record to begin inputting that patient's data. Might I really just be
dealing with a sorting issue?

So help me understand, please: are you saying that there's no way I should
get information to pull from a second table without a DLookup, a subform, or
a query, and that the multi table/one form concept doesn't exist?

I'm confused, because that's really what I did, just not beautifully; I got
the idea from an Access 2000 book (yes, I know I'm old-fashioned!), in a
section discussing how to create plain ol' regular forms (i.e., not
subforms). I mean, if it's not allowed, I'm wondering, would it have let me
get it to the point of rudimentary functionality?

Now I gotta see if we're on the same page--bear with me...so if I remember
correctly, if one uses the Form Wizard (me=beginner), that FW has you pick
from a drop-down which table you're basing your form on, and then it gives
you the opportunity to go back to that drop-down and pick more tables to
include controls from in your same form. (It didn't say anything about
designating one table as main and others for subform.) So then when you're in
form design view and you hit your little list of available controls, you see
controls not just from your main table but whatever other controls you
selected to include from the additional tables. Where you would normally
have set up DLookups for those additional controls, here you simply click and
drag those controls onto your form as though they were from the original
table. Actually, I found it kind of annoying that it's not more obvious
which controls are bound to which table.

Meantime, let's assume I'm wrong and it's not legit to do what I described
above even though it can be made to function to some degree. So then my next
choice is either form/subform or query.

With the query, though, I'm wondering whether I'll have the same sorting
issue. So how do you get a form to start sorting again in the order the
records were added? (Honestly, I read that darn book again but none of their
stuff worked this time.) Seems like there's a specific FILTER concept that
lets you specify last added, but not one for a query? Is there some sort of
"get last" code that I could somehow stick into that macro I'm already using?
I've sooo not picked up code yet...

THANK YOU for your patience!! I know that Concise and I aren't exactly
buddies...
 
K

Klatuu

If there is a one to one relationship between patients and tests, you may try
creating a query that included fields from both tables in one form.

As I said before, one form = one recordset. That's the way it is, that's
the way it has always been. The recordset can be a table or a query.
Depending on the relationship between tables, a query may or may not be
updatabable.

No matter how bad you want to use a screwdriver as a chisle, you are going
to get frustrated and only mess up a good screwdriver.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top