The extra bit about NoMatch should take care of that:
Private Sub Combo34_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[SSN] = '" & Me![Combo34] & "'"
If rs.NoMatch Then
Me.Combo34 = ""
MsgBox "No Patient with this ID"
Else
Me.Bookmark = rs.Bookmark
End If
End Sub
You will note that I left out "If Not rs.EOF Then". I don't think it is
needed since you are testing NoMatch, but to be honest I am still a bit
unclear about how to use EOF (end of file) and BOF (beginning of file)
except when attempting to navigate to the next of previous record when that
is not possible. For instance, if you are on the last record and attempt to
go to the next record, EOF will be true. In the context of the code created
by the wizard I am not quite sure what it does. I might have guessed it was
to allow for no record being found, but if so you have seen it does not seem
to work as you would like in that context. I have tested using my method,
which seems to work, but I expect the EOF version of the code will work too.
If you are at a record and try to move to a non-existant record, it will not
work, and will leave you at the current record, as I recall. It is also
possible to ask if the user wants to create a new record, or to go to the
first record, or whatever, but we can take that up as needed. First be sure
it works if no record is found.
BTW, if SSN is Social Security Number, be very careful. There are legal
implications to allowing a person's SSN to be obtained by unauthorized
persons. Access, especially with no security applied, is not a secure
environment for sensitive or personal information.
Shannon said:
I used an unbound combo box on the form for the patient number. The form
contains the patient information. The sub-form contains the appointment
informtion. Here is the code attached to that combo box.
Private Sub Combo34_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[SSN] = '" & Me![Combo34] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
I did a test, as i said before. if the person is in the database it will
pull their information. if the person is not in the database, then it adds
in
someone elses information. It does not leave the rest of the fields blank
when the person is not in the database already.
BruceM said:
Post the code you used, and describe the errors. Did you use the text
box
code? If so, is it in an unbound text box? A text box or combo box for
searching needs to be unbound.
It may help if you describe more about the structure. Again, is this the
form/subform I described? If so, in which is the text box or combo box
located, the form or the subform?
It works, and it doesn't. If the patient is already in the system then
it
does pull up the persons information, but if the person is not in the
system
then it adds someone elses information. I just did a test with all 1's,
2's
and 3's for the patient number and A's, B's, and C's for their
information
and when i entered in a patient number of all 4's it pulled the
informaiton
entered in for the test person of all 2's. That isn't good. if you
enter
in a
new person and it pulls another persons information unless you know the
person and their information then you will not know that the
information
belongs to someone else.
So, I tried the code that you input in. and then i had errors.
:
Again, you can type the number into the combo box just as you would a
text
box. You do not have to scroll through thousands of records. Also, a
combo
box gives you the option of adding the patient name (again, you can
type
it
in).
Do you have a main form and a subform as I suggested? If not, what do
you
have? If so, have you tried adding a combo box using the wizard as I
suggested? If so, did it work?
If you want to use a text box, and if you have a main form and a
subform
as
I suggested, you can create an unbound text box on the form (in the
header,
maybe) with something like the following as its After Update event:
Private Sub txtPatientID_AfterUpdate()
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[PatientID] = " & Me.txtPatientID
If rs.NoMatch Then
Me.txtPatientID = ""
MsgBox "No Patient with this ID"
Else
Me.Bookmark = rs.Bookmark
End If
End Sub
Yes, the patient record only exists when they have cancelled.
Otherwise,
all
of the information is maintained in a regular medical record, of
witch
we
do
not maintain. The problem is that the patients hardly ever come
through
for
appointments on a regular basis. They are only seen twice within a
1-2
week
period once a year. Worst case senario, they get seen two or three
times
over
two or three years. We don't have to worry about name changes,
address
changes, and so on. The patient number is the only constant. It is
as
unique
as one's Social Security Number. It will never be used on another
person.
With that, having a combo box would be too dificult. We are talking
about
thousands of people here. Thousands of people that we don't have to
maintain
and don't see all that often. It is rare to see the same person two
or
threee
years in a row. And having to scroll through thousands of people is
very
time
consuming. I could see using a combo box if the patients were with
us
on a
constant basis, however, they are not.
if the person has had to be entered in for a cancelled appointment
once,
and
we go to put them in again we don't want to type everything out only
to
find
they are in already. After typing in the Patient number we want the
rest
of
the form to auto update/fill. I know this might not make sence, but
it
is
working really well. and would work even better if we werent typing
in
the
same information over and over for someone that is already in the
database.
:
What do you mean when you say you created a blank database? Do I
understand
that the patient record exists only when a patient has cancelled,
and
that
there is no connection with any existing patient listing? That is,
is
this
database a listing only of patients who have cancelled
appointments?
If
so,
that would mean you need to copy patient information from one table
to
another, which is going to be a maintenance headache at the least
if a
patient moves, gets another phone number, changes their name, etc.
It would be much better if you could link to an existing Patient
table.
If
you can't, the question seems to be how you can determine whether a
patient
has cancelled before (i.e. has a record in the database). I have
suggested
that you use a combo box to select the patient name (actually, I
said
"select from a list"). I will outline the procedure. If you
prefer
to
type
the number into a text box rather than selecting the name or number
from
a
list, you can adapt the procedure.
First, you need a main form based on the Customer table, and a
subform
based
on the related MissedAppointments table. The subform could have
the
Default
View set to Continuous if you want to see several appointment
records
at
once. Enter the patient information into the main form; then you
can
create
appointment records for the patient.
Use the combo box wizard to create a combo box that will go to a
record
on
your form. To use the wizard, open the toolbox. Be sure the magic
wand
icon is highlighted. Click the combo box icon, and click onto the
form.
Follow the prompts to create a combo box that will find a record on
the
form. If you see that the patient number/name is not there you can
create a
new patient record on the main form.
You can still type the number into the text box, or you can select
it
from
the combo box list. If you want to use a text box so that there is
no
option of selecting from a list you can adapt the combo box code.
Post
back
if you need help with that.
I created this data base for a department in a medical building.
They
are
trying to track their patients/customers that either do not show
up
for
their
appointments or that the department has to cancel. Along with
that,
the
department works with different companies and is trying to find
out
if
there
is a trend in the canceled appointments. (Are the majority of
canceled
or
no
show appointments comming from one company? Are there specific
patients/customers that constantly cancel or don't show up for
their
appointment?) This department is getting repremanded for
patient/customer
complaints when the patient/customer is the one that is creating
the
problems. All of the patients/customers need to be seen by a
certain
date
and
when there are a ton of patients/customers that cancel or don't
show
up
that
is one appointment that the medical department could have used to
see a