Configuring visibility for a tab control page by setting an On Current event on a continuous form (1 Viewer)

Arcanant

New member
Local time
Today, 20:00
Joined
Jun 4, 2022
Messages
4
This is my first question post so sorry if not everything is clear, I am still getting the hunk of it. I am a very novice beginner willing to learn ^_^

I am trying to set up an order form for purchase of optionally more than one product that each have different customization options based on their category they belong to. The main form contains details about order number, customer, destination and in a subform a continuous form for adding the different products.
So far, I made (in the subform) a combo box that autofill based on choice the standard fields that is for every product. I added a tab control with different pages for each category of product that includes the fields for the different options. I am trying to set up a trigger event to change the visibility of the pages based on the category that gets autofill from the combo box choice when a product is chosen. My attempt:

VBA set an on Current event on the sub(continuous)form

Code:
if me.category.value = Chair then
Me.tabctrlproductoptions.Pages(Chair).visible =True else
Me.tabctrlproductoptions.Pages(Chair).visible = False
end if


I am getting an Error message when I try to reopen the form

Object doesn't support this property or method (Error 438)​

If anyone has a take on this, I would very much appreciate it. I am open to alternative methods and ideas if what I try to do is not possible. Thank you in advance for your input.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:00
Joined
Oct 29, 2018
Messages
19,135
Hi. If Chair is the name of your tab page, then try enclosing it in quotes. For example:

.Pages("Chair")

Same thing with your If statement.

If Me.Category.Value = "Chair"
 

Arcanant

New member
Local time
Today, 20:00
Joined
Jun 4, 2022
Messages
4
So I configured the code like this

Code:
Option Compare Database


Private Sub comboChooseProduct_AfterUpdate()






End Sub


Private Sub Form_Current()


If Me.category.Value = "Chair" Then
Me.TabCtlproductoptions.Pages("Chair").Visible = True
ElseIf Not Me.category.Value = "Chair" Then
Me.TabCtlproductoptions.Pages("Chair").Visible = False
End If


End Sub

I am not getting any errors but it doesn't seem to do what I ask of it. Any ideas?
 

mike60smart

Registered User.
Local time
Today, 18:00
Joined
Aug 6, 2017
Messages
1,235
So I configured the code like this

Code:
Option Compare Database


Private Sub comboChooseProduct_AfterUpdate()






End Sub


Private Sub Form_Current()


If Me.category.Value = "Chair" Then
Me.TabCtlproductoptions.Pages("Chair").Visible = True
ElseIf Not Me.category.Value = "Chair" Then
Me.TabCtlproductoptions.Pages("Chair").Visible = False
End If


End Sub

I am not getting any errors but it doesn't seem to do what I ask of it. Any ideas?
Hi
Are you able to upload the database without any Confidential data?
 

Arcanant

New member
Local time
Today, 20:00
Joined
Jun 4, 2022
Messages
4
Hello and ty very much. I can since all the info is fake anyway for practice but I am afraid everything is in Greek ... 😕 I have split the tables and the forms in separate files. The tables are in the folder "ΠΙΝΑΚΕΣ", you can update and re-link them at the Styllas(1).accdb file. The form I am trying to manipulate is the ΦΟΡΜΑ_ΠΑΡΑΓΓΕΛΙΩΝ_ΠΩΛΗΤΩΝ. The field in the sub form that I am referencing at is the ΚΑΤΗΓΟΡΙΑ, the combo box is called ΕΠΙΛΟΓΗ ΠΡΟΪΟΝΤΟΣ. It is a bit too much to translate everything but I am willing to go in live chat to translate live any relevant info.
 

Attachments

  • ΒΑΣΗ ΔΕΔΟΜΕΝΩΝ.zip
    525.8 KB · Views: 67

mike60smart

Registered User.
Local time
Today, 18:00
Joined
Aug 6, 2017
Messages
1,235
Hello and ty very much. I can since all the info is fake anyway for practice but I am afraid everything is in Greek ... 😕 I have split the tables and the forms in separate files. The tables are in the folder "ΠΙΝΑΚΕΣ", you can update and re-link them at the Styllas(1).accdb file. The form I am trying to manipulate is the ΦΟΡΜΑ_ΠΑΡΑΓΓΕΛΙΩΝ_ΠΩΛΗΤΩΝ. The field in the sub form that I am referencing at is the ΚΑΤΗΓΟΡΙΑ, the combo box is called ΕΠΙΛΟΓΗ ΠΡΟΪΟΝΤΟΣ. It is a bit too much to translate everything but I am willing to go in live chat to translate live any relevant info.
Just sent you a Conversation request
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:00
Joined
Feb 19, 2002
Messages
36,837
Tab pages are intended for use when you have a lot data about a single main record. Tab pages with or without subforms are a neat way of organizing the data and convenient way for the user to switch from tab to tab depending on what he is interested in seeing.

That doesn't seem to be your situation. You have mutually exclusive subforms so although you could put them on tabs, it doesn't help you because you don't want people clicking on a tab with an irrelevant subform. So, it is best to just use one subform control and substitute the name of the subform you want to load each time the user moves to a new record.

Add a new field to the Category table to hold the name of the subform used for that category. Then you need code in two events. The Current event and the AfterUpdate event of the MainForm. Also, you probably need code to prevent the user from changing the Category once the record is saved.

In the Current event:
Code:
If Me.NewRecord = False Then
    Me.SubformControl.ControlSource = Me.cboCategory.Column(2)
Else
    Me.SubformControl.ControlSource = Null
End if

Once you add the new field to the Category table, you also need to add it to the RowSource of the Category combo. Assuming the Category RowSource is three columns - CategoryID, CategoryName, FormName, then .Column(2) refers to the FormName. The RowSource is a zero-based array. Therefore the first column is .Column(0) and the third is .Column(2). So, change this as necessary to refer to the FormName.

Then the code in the AfterUpdate event of the main form:
Code:
Me.SubformControl.ControlSource = Me.cboCategory.Column(2)

This is one of many situations where you can use data to minimize the code you need and also make the app easier to maintain since all you need to do is add a row to a table instead of modifying code in a form.
 

Users who are viewing this thread

Top Bottom