how to make dynamic sub form like the north wind db

siamandm
BronzeLounger
Posts: 1323
Joined: 01 May 2016, 09:58

how to make dynamic sub form like the north wind db

Post by siamandm »

hello all,

in the north wind db, there is a form company details, when you open it it has a sub form which changes based on the company type
if its vendor the subfrm will be PO, if the company is customer it will change to Order ! how they made this please someone could explain this plz?
Screenshot 2024-09-25 161806.png
You do not have the required permissions to view the files attached to this post.

User avatar
Gasman
2StarLounger
Posts: 157
Joined: 22 Feb 2022, 09:04

Re: how to make dynamic sub form like the north wind db

Post by Gasman »

Follow the code

Code: Select all

Private Sub cboCompanyTypeID_AfterUpdate()
10        On Error GoTo Err_Handler

20        ManageFormOptions

Exit_Handler:
30        Exit Sub

Err_Handler:
40        clsErrorHandler.HandleError Me.Name, "cboCompanyTypeID_AfterUpdate", True
50        Resume Exit_Handler
End Sub
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

User avatar
Gasman
2StarLounger
Posts: 157
Joined: 22 Feb 2022, 09:04

Re: how to make dynamic sub form like the north wind db

Post by Gasman »

Screenshot 2024-09-25 145138.png
Perhaps start using this icon on each form?
You do not have the required permissions to view the files attached to this post.
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

siamandm
BronzeLounger
Posts: 1323
Joined: 01 May 2016, 09:58

Re: how to make dynamic sub form like the north wind db

Post by siamandm »

Dear Gasman,
thank you for the suggestion, i did read the information but i couldn't find the answer to my question :(

User avatar
Gasman
2StarLounger
Posts: 157
Joined: 22 Feb 2022, 09:04

Re: how to make dynamic sub form like the north wind db

Post by Gasman »

OK, so follow the code I posted.

However in that Help it states

In the Form_Current event, the following occurs:

Change a sub form caption and source object at runtime by calling the sub ManageFormOptions(). This subroutine is called from multiple places in this form.

:sad:
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

siamandm
BronzeLounger
Posts: 1323
Joined: 01 May 2016, 09:58

Re: how to make dynamic sub form like the north wind db

Post by siamandm »

I found that its related to the cboCompanytype after update event

but I dont know what is enumCompanyType ?

Code: Select all

Private Sub ManageFormOptions()
10        On Error GoTo Err_Handler

20        With Me
30            .sfrmOrders.SourceObject = ""

40            .Caption = .txtCompanyType.Value

              'Set the subform in the upper right section based on Company Type
50            Select Case .cboCompanyTypeID.Value
                  Case enumCompanyType.ctCustomer
60                    .sfrmOrders.SourceObject = "sfrmCompanyDetail_CustomerOrders"
70                    .lblsfrmOrders.Caption = "Orders"
80                Case enumCompanyType.ctShipper
90                    .sfrmOrders.SourceObject = "sfrmCompanyDetail_ShipperOrders"
100                   .lblsfrmOrders.Caption = "Orders Shipped"
110               Case enumCompanyType.ctVendor
120                   .sfrmOrders.SourceObject = "sfrmCompanyDetail_VendorPurchaseOrders"
130                   .lblsfrmOrders.Caption = "Purchase Orders"
140               Case enumCompanyType.ctNorthwind
150                   .sfrmOrders.SourceObject = ""   'Northwind itself does not place orders.
160                   .lblsfrmOrders.Caption = ""
170               Case Else
180                   Debug.Assert False      'Unexpected company type is not yet implemented.
190           End Select

200       End With

Exit_Handler:
210       Exit Sub

Err_Handler:
220       clsErrorHandler.HandleError "Form_frmCompanyDetail", "ManageFormOptions"
230       Resume Exit_Handler
End Sub

User avatar
Gasman
2StarLounger
Posts: 157
Joined: 22 Feb 2022, 09:04

Re: how to make dynamic sub form like the north wind db

Post by Gasman »

Have you tried a Find? :groan:
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

George Hepworth
NewLounger
Posts: 18
Joined: 13 Jun 2024, 12:24

Re: how to make dynamic sub form like the north wind db

Post by George Hepworth »

Enums are a significant element in NW Developer. Here's an explanation of what Enums are and how they can be used:
https://learn.microsoft.com/en-us/offic ... -statement

One of the reasons we used Enums is that they support representing numerical values (such as the CompanyTypeIDs) as meaningful words in code. This is sometimes referred to as eliminating "magical numbers".

For example.
Case enumCompanyType.ctCustomer

means the same thing as

Case 1

In other words 1 would be a "Magical Number" in that there's no obvious way to figure out what it means. On the other hand
enumCompanyType.ctCustomer is much more clearly a reference to a Customer company type.

As Gasman suggested, a search through the code will prove to be a valuable learning tool you can use now and in the future.

siamandm
BronzeLounger
Posts: 1323
Joined: 01 May 2016, 09:58

Re: how to make dynamic sub form like the north wind db

Post by siamandm »

Dear George,

thank you very much for your explanation