main form/subform

P

patti

I have a main form that has all the patient info, including medical record #.
One of the tabbed sub-forms is for hospital stay info. If the patient has an
admitting date, i need the user to enter the med rec # on the main form. Not
quite sure how to go about this. Any help would be appreciated.
 
J

John W. Vinson/MVP

I have a main form that has all the patient info, including medical record #.
One of the tabbed sub-forms is for hospital stay info. If the patient has an
admitting date, i need the user to enter the med rec # on the main form. Not
quite sure how to go about this. Any help would be appreciated.

Well, I'm not sure just how your form is structured, but code like
this might work. Put code in the AfterUpdate event of the admitting
date field (or some field which automatically causes the admitting
date field to be filled in, or perhaps the subform's AfterUpdate
event):

If Not IsNull(Me!txtAdmittingDate) Then
If IsNull(Parent!txtMedRecNo) Then
MsgBox "Please fill in medical record number", vbOKOnly
Parent!txtMedRecNo.SetFocus
End If
End If
 
P

patti

Thanks for the help, John.

The names are unwieldy but:

My whole form is named "bPatientInfoForm".
It has 3 tabs. On the tab 1 is a textbox for "PatientMedicalRecord#".
Tab 3 has a form named "formHospVisite" with a textbox "TextAdmitDate"

My code:

Private Sub TextAdmitDate_AfterUpdate()

If Not IsNull(Me!textAdmitDate) Then
If IsNull(bPatientInfoForm!PatientMedicalRecord#) Then
MsgBox "Please fill in medical record number", vbOKOnly
bPatientInfoForm!PatientMedicalRecord#.SetFocus
End If
End If

End Sub

I get the compile error: variable not defined.highlightting bPatientInfoForm.
not sure where i am going wrong.
 
J

John W. Vinson/MVP

If Not IsNull(Me!textAdmitDate) Then
If IsNull(bPatientInfoForm!PatientMedicalRecord#) Then
MsgBox "Please fill in medical record number", vbOKOnly
bPatientInfoForm!PatientMedicalRecord#.SetFocus
End If
End If

End Sub

I get the compile error: variable not defined.highlightting bPatientInfoForm.
not sure where i am going wrong.

If the code (the textbox textAdmitDate) is on bPatientInfoForm then
use

Me![PatientMedicalRecord#]

(Note the brackets - recommended if you unwisely use special
characters like blank or # in control names).

If it's on a different for use

Forms!bPatientInfoForm![PatientMedicalRecord#]

You can't just use the form name by itself - Access has no way of
knowing what kind of object you're referring to.
 
P

patti

Hi John-

Thanks for the help.

A question:

How does using the "Forms!" make access find the object? Hard to explain my
question but is it kind of like access makes "inner" folders for each object
type (the way windows explorer works)? I am really curious about the inner
workings of access.

John W. Vinson/MVP said:
If Not IsNull(Me!textAdmitDate) Then
If IsNull(bPatientInfoForm!PatientMedicalRecord#) Then
MsgBox "Please fill in medical record number", vbOKOnly
bPatientInfoForm!PatientMedicalRecord#.SetFocus
End If
End If

End Sub

I get the compile error: variable not defined.highlightting bPatientInfoForm.
not sure where i am going wrong.

If the code (the textbox textAdmitDate) is on bPatientInfoForm then
use

Me![PatientMedicalRecord#]

(Note the brackets - recommended if you unwisely use special
characters like blank or # in control names).

If it's on a different for use

Forms!bPatientInfoForm![PatientMedicalRecord#]

You can't just use the form name by itself - Access has no way of
knowing what kind of object you're referring to.
 
J

John W. Vinson/MVP

Hi John-

Thanks for the help.

A question:

How does using the "Forms!" make access find the object? Hard to explain my
question but is it kind of like access makes "inner" folders for each object
type (the way windows explorer works)? I am really curious about the inner
workings of access.

You're basically correct. A lot of the Access object model syntax
relies on "Collections" - there is a Forms collection which consists
of all the open Forms, a Tabledefs collection which consists of all
the defined tables, etc. A Collection contains objects, which may
themselves be collections; e.g. each table object in the Tabledefs
collection contains a Fields collection.

You can open the VBA editor by editing any module or by typing Ctrl-G
and use the "Object Browser" tool on the toolbar to find out more than
you ever wanted to know about the structure... start with the Database
collection.
 
P

patti

As always, thanks for helping.

John W. Vinson/MVP said:
You're basically correct. A lot of the Access object model syntax
relies on "Collections" - there is a Forms collection which consists
of all the open Forms, a Tabledefs collection which consists of all
the defined tables, etc. A Collection contains objects, which may
themselves be collections; e.g. each table object in the Tabledefs
collection contains a Fields collection.

You can open the VBA editor by editing any module or by typing Ctrl-G
and use the "Object Browser" tool on the toolbar to find out more than
you ever wanted to know about the structure... start with the Database
collection.
 

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