SubForm Problem

  • Thread starter Thread starter Paul Scott
  • Start date Start date
P

Paul Scott

I have a form with a subform. I have a field called
Facility on the form frmBedCleaningEntry and a
RequestedBy on the subform.

If the facility is Hazelwood then the focus is set to
ExtNo Field. If it's not Hazelwood then NA is placed in
the ExtNo field, a phone # is placed in the PhoneNo field
and the focus is set to the CleaningDescrip field.

I have no problem getting the code to work on a single
form but have tried everything but can't get the code to
work with the subform.

Could someone look over the enclosed code and see if they
can see why the code isn't working?

I've always had problems in the past getting the focus
from the form to the subform. What's the secret getting
the focus to work from a form to a subform?

Thanks for the help,

Paul


Private Sub RequestedBy_AfterUpdate()

If [frmBedCleaningEntry]![Facility] = "Hazelwood"
Then
PhoneNo = "NA"
ExtNo.SetFocus

End If

If [frmBedCleaningEntry]![Facility] = "Meadows" Then
PhoneNo = "555-1234"
ExtNo = "NA"
CleaningDescrip.SetFocus

End If

If [frmBedCleaningEntry]![Facility] = "Windsong" Then
PhoneNo = "555-2345"
ExtNo = "NA"
CleaningDescrip.SetFocus

End If

If [frmBedCleaningEntry]![Facility] = "DelMaria" Then
PhoneNo = "555-3456"
ExtNo = "NA"
CleaningDescrip.SetFocus

End If

End Sub
 
first, what is the name of the subform *control* in the main form? this is
where folks usually miss the boat.
open the main form in design view.
double click the blank *box* in the upper left corner, where the horizontal
and vertical rulers meet, to open the Properties box.
click *once only* on the subform control, to select it. look at the Name
property in the Properties box - that's the name of the subform control. (it
may be different from the name of the subform object in the database window,
which is what confuses many people.)
when you write code in the main form that references a control in the
subform, use the following reference:

Me!NameOfSubformControlOnMainForm!NameOfTheControlOnTheSubform

if you need to reference a form property of the subform, again from the main
form, use the following reference:

Me!NameOfSubformControlOnMainForm.Form

also, fyi, suggest you replace the multiple If statements with a Select Case
statement, as

Select Case Me!Facility
Case "Hazelwood"
PhoneNo = "NA"
ExtNo.SetFocus
Case "Meadows"
PhoneNo = "555-1234"
ExtNo = "NA"
CleaningDescrip.SetFocus
Case "next name"
(etc, etc, etc,
you can also use Case Else when needed, which works the same as
Else in an If Then Else statement)
(always ending with...)
End Select

the system processes the code written beneath the first Case that matches
the value of Select Case, skips all the other Cases, and goes to End Select.

hth
 
I just wanted to say I got it to work.

I really do appreciate the help you and everyone give
within this newsgroup.

Paul
-----Original Message-----
first, what is the name of the subform *control* in the main form? this is
where folks usually miss the boat.
open the main form in design view.
double click the blank *box* in the upper left corner, where the horizontal
and vertical rulers meet, to open the Properties box.
click *once only* on the subform control, to select it. look at the Name
property in the Properties box - that's the name of the subform control. (it
may be different from the name of the subform object in the database window,
which is what confuses many people.)
when you write code in the main form that references a control in the
subform, use the following reference:

Me!NameOfSubformControlOnMainForm! NameOfTheControlOnTheSubform

if you need to reference a form property of the subform, again from the main
form, use the following reference:

Me!NameOfSubformControlOnMainForm.Form

also, fyi, suggest you replace the multiple If statements with a Select Case
statement, as

Select Case Me!Facility
Case "Hazelwood"
PhoneNo = "NA"
ExtNo.SetFocus
Case "Meadows"
PhoneNo = "555-1234"
ExtNo = "NA"
CleaningDescrip.SetFocus
Case "next name"
(etc, etc, etc,
you can also use Case Else when needed, which works the same as
Else in an If Then Else statement)
(always ending with...)
End Select

the system processes the code written beneath the first Case that matches
the value of Select Case, skips all the other Cases, and goes to End Select.

hth


I have a form with a subform. I have a field called
Facility on the form frmBedCleaningEntry and a
RequestedBy on the subform.

If the facility is Hazelwood then the focus is set to
ExtNo Field. If it's not Hazelwood then NA is placed in
the ExtNo field, a phone # is placed in the PhoneNo field
and the focus is set to the CleaningDescrip field.

I have no problem getting the code to work on a single
form but have tried everything but can't get the code to
work with the subform.

Could someone look over the enclosed code and see if they
can see why the code isn't working?

I've always had problems in the past getting the focus
from the form to the subform. What's the secret getting
the focus to work from a form to a subform?

Thanks for the help,

Paul


Private Sub RequestedBy_AfterUpdate()

If [frmBedCleaningEntry]![Facility] = "Hazelwood"
Then
PhoneNo = "NA"
ExtNo.SetFocus

End If

If [frmBedCleaningEntry]![Facility] = "Meadows" Then
PhoneNo = "555-1234"
ExtNo = "NA"
CleaningDescrip.SetFocus

End If

If [frmBedCleaningEntry]![Facility] = "Windsong" Then
PhoneNo = "555-2345"
ExtNo = "NA"
CleaningDescrip.SetFocus

End If

If [frmBedCleaningEntry]![Facility] = "DelMaria" Then
PhoneNo = "555-3456"
ExtNo = "NA"
CleaningDescrip.SetFocus

End If

End Sub


.
 
Back
Top