auto-select subform

M

miss031

I would like to have the selection that the user makes on the main form to
determine which sub-form is opened.

If the user clicks on one command (or toggle?) button I would like one
sub-form to open up to record further information of one type, if the other
main form control is clicked, I would like a different subform to open for a
different type of data to be recorded.
 
W

Wayne-I-M

Hi

You could use domething like this. I have add a popup message if no choice
is made to ButtonMiss031

Add an option group with a number of buttons (I have shown three but you can
have as many as you like). Next add a button (as I said I have called it
ButtonMIss031). I tend to use a combination of option group and button so as
to stop too many mistakes by users

The forms I have coded to open are
SubFormA
SubFormB
SubFormC

You will note that I have put a filter on to each form
So that it will open to a specific record (you could simply use Me.SomeField
which would have the benifit of letting you have a "dinamic" filter)
The filters I have used are
ABC
XYZ
OPQ

Have a try with this and if you have problems then post back and I will try
and help




Private Sub ButtonMiss031_Click()

If (Forms!FormName!OptionGroupName = 1) Then
DoCmd.OpenForm "SubFormNameA", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=ABC", , acNormal
End If
If (Forms!FormName!OptionGroupName = 2) Then
DoCmd.OpenForm "SubFormNameB", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=XYZ", , acNormal
End If
If (Forms!FormName!OptionGroupName = 3) Then
DoCmd.OpenForm "SubFormNameC", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=OPQ", , acNormal
End If
‘This will add a pop-up message if no choice is made’
If (Eval("[Forms]![OptionGroupName]![SelectMode] Is Null")) Then
MsgBox "You must make a choice .", vbInformation, "No choice made"
End If

End Sub


You can delete most section of this code without it failing so have a play
around with it if you're not sure about coding forms.


Hope this helps


--
Wayne
Manchester, England.
Enjoy whatever it is you do
Scusate,ma il mio Inglese fa schiffo :)
Percio se non ci siamo capiti, mi mandate un
messagio e provero di spiegarmi meglio.
 
M

miss031

I am getting a compile error: syntax error.

cmd_select_subform is the command button to open the subform
pre_clerked_items is the main form
option_group_select_subform is the option group
subtable_misc_items_info is the first sub-form
subtable_vehicle basic info is the second sub-form

I excluded the filter lines right now, becuase I don't think I want a
filter, I think I want to enter a new record.

Private Sub cmd_select_subform_Click()

If (Forms!pre_clerked_items!optiongroup_select_subform = 1) Then
DoCmd.OpenForm "subtable_misc items info", acNormal, "",
'"[Forms]![subtable_misc_items_info]![FieldName]=ABC", , acNormal
End If
If (Forms!pre_clerked_items!optiongroup_select_subform = 2) Then
DoCmd.OpenForm "subtable_vehicle_basic_info", acNormal, "",
'"[Forms]![subtable_vehicle_basic_info]![FieldName]=XYZ", , acNormal
End If
'This will add a pop-up message if no choice is made
If (Eval("[Forms]![optiongroup_select_subform]![SelectMode] Is Null"))
Then
MsgBox "You must make a choice .", vbInformation, "No choice made"
End If

End Sub

Wayne-I-M said:
Hi

You could use domething like this. I have add a popup message if no choice
is made to ButtonMiss031

Add an option group with a number of buttons (I have shown three but you can
have as many as you like). Next add a button (as I said I have called it
ButtonMIss031). I tend to use a combination of option group and button so as
to stop too many mistakes by users

The forms I have coded to open are
SubFormA
SubFormB
SubFormC

You will note that I have put a filter on to each form
So that it will open to a specific record (you could simply use Me.SomeField
which would have the benifit of letting you have a "dinamic" filter)
The filters I have used are
ABC
XYZ
OPQ

Have a try with this and if you have problems then post back and I will try
and help




Private Sub ButtonMiss031_Click()

If (Forms!FormName!OptionGroupName = 1) Then
DoCmd.OpenForm "SubFormNameA", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=ABC", , acNormal
End If
If (Forms!FormName!OptionGroupName = 2) Then
DoCmd.OpenForm "SubFormNameB", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=XYZ", , acNormal
End If
If (Forms!FormName!OptionGroupName = 3) Then
DoCmd.OpenForm "SubFormNameC", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=OPQ", , acNormal
End If
‘This will add a pop-up message if no choice is made’
If (Eval("[Forms]![OptionGroupName]![SelectMode] Is Null")) Then
MsgBox "You must make a choice .", vbInformation, "No choice made"
End If

End Sub


You can delete most section of this code without it failing so have a play
around with it if you're not sure about coding forms.


Hope this helps


--
Wayne
Manchester, England.
Enjoy whatever it is you do
Scusate,ma il mio Inglese fa schiffo :)
Percio se non ci siamo capiti, mi mandate un
messagio e provero di spiegarmi meglio.


miss031 said:
I would like to have the selection that the user makes on the main form to
determine which sub-form is opened.

If the user clicks on one command (or toggle?) button I would like one
sub-form to open up to record further information of one type, if the other
main form control is clicked, I would like a different subform to open for a
different type of data to be recorded.
 
W

Wayne-I-M

Here you go

Set this on the OnClick event of the button (cmd_select_subform)

Private Sub cmd_select_subform _Click()
If (Forms! pre_clerked_items!option_group_select_subform = 1) Then
DoCmd.OpenForm " subtable_misc_items_info", acNormal, "", "", ,
acNormal
End If
If (Forms! pre_clerked_items!option_group_select_subform = 2) Then
DoCmd.OpenForm " subtable_vehicle basic info", acNormal, "", "", ,
acNormal
End If
End Sub


I have taken off the filter and I have removed the the popup message. I
find though that popup are sometime are useful for users for the first week
or so after I have upgraded a DB. You can add it back in later if you want.

To check the Option Group options open the form in design view and select
the option group. Click each option and look at the data colum of the
properties box to make sure you have the subforms in the right order.

Hope this helps


--
Wayne
Manchester, England.
Enjoy whatever it is you do
Scusate,ma il mio Inglese fa schiffo :)
Percio se non ci siamo capiti, mi mandate un
messagio e provero di spiegarmi meglio.


miss031 said:
I am getting a compile error: syntax error.

cmd_select_subform is the command button to open the subform
pre_clerked_items is the main form
option_group_select_subform is the option group
subtable_misc_items_info is the first sub-form
subtable_vehicle basic info is the second sub-form

I excluded the filter lines right now, becuase I don't think I want a
filter, I think I want to enter a new record.

Private Sub cmd_select_subform_Click()

If (Forms!pre_clerked_items!optiongroup_select_subform = 1) Then
DoCmd.OpenForm "subtable_misc items info", acNormal, "",
'"[Forms]![subtable_misc_items_info]![FieldName]=ABC", , acNormal
End If
If (Forms!pre_clerked_items!optiongroup_select_subform = 2) Then
DoCmd.OpenForm "subtable_vehicle_basic_info", acNormal, "",
'"[Forms]![subtable_vehicle_basic_info]![FieldName]=XYZ", , acNormal
End If
'This will add a pop-up message if no choice is made
If (Eval("[Forms]![optiongroup_select_subform]![SelectMode] Is Null"))
Then
MsgBox "You must make a choice .", vbInformation, "No choice made"
End If

End Sub

Wayne-I-M said:
Hi

You could use domething like this. I have add a popup message if no choice
is made to ButtonMiss031

Add an option group with a number of buttons (I have shown three but you can
have as many as you like). Next add a button (as I said I have called it
ButtonMIss031). I tend to use a combination of option group and button so as
to stop too many mistakes by users

The forms I have coded to open are
SubFormA
SubFormB
SubFormC

You will note that I have put a filter on to each form
So that it will open to a specific record (you could simply use Me.SomeField
which would have the benifit of letting you have a "dinamic" filter)
The filters I have used are
ABC
XYZ
OPQ

Have a try with this and if you have problems then post back and I will try
and help




Private Sub ButtonMiss031_Click()

If (Forms!FormName!OptionGroupName = 1) Then
DoCmd.OpenForm "SubFormNameA", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=ABC", , acNormal
End If
If (Forms!FormName!OptionGroupName = 2) Then
DoCmd.OpenForm "SubFormNameB", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=XYZ", , acNormal
End If
If (Forms!FormName!OptionGroupName = 3) Then
DoCmd.OpenForm "SubFormNameC", acNormal, "",
"[Forms]![SubFormName1]![FieldName]=OPQ", , acNormal
End If
‘This will add a pop-up message if no choice is made’
If (Eval("[Forms]![OptionGroupName]![SelectMode] Is Null")) Then
MsgBox "You must make a choice .", vbInformation, "No choice made"
End If

End Sub


You can delete most section of this code without it failing so have a play
around with it if you're not sure about coding forms.


Hope this helps


--
Wayne
Manchester, England.
Enjoy whatever it is you do
Scusate,ma il mio Inglese fa schiffo :)
Percio se non ci siamo capiti, mi mandate un
messagio e provero di spiegarmi meglio.


miss031 said:
I would like to have the selection that the user makes on the main form to
determine which sub-form is opened.

If the user clicks on one command (or toggle?) button I would like one
sub-form to open up to record further information of one type, if the other
main form control is clicked, I would like a different subform to open for a
different type of data to be recorded.
 
Top