Open second form with comand

tihmir

Registered User.
Local time
Today, 04:32
Joined
May 1, 2018
Messages
257
Hi, all
I am trying to open second form with comand button
I have two forms

Form_1 – “Filter”
Form_2 – “Objects”
In the Form_1 – “Filter” I have 3 comboboxes:
1-Regions (cbo_Regions)
2-Cities (cbo_Cities)
3-Тypes of objects (cbo_TypeOfObjects)
I bild comand button to open second form (Form_2 – “Objects”).

1st - When it open I want to open all selected type of object (cbo_TypeOfObject) for example - all hotels
2nd - When it open I want to open all hotels (cbo_TypeOfObjects), but only in the selected sity in cbo_Cities
 

Attachments

First, to accomplish what you posted about you would use the DoCmd.OpenForm method (https://docs.microsoft.com/en-us/office/vba/api/access.docmd.openform), being sure to build a filter string to limit it to just the values you want to show when you open the form.

Second, you shouldn't be worrying about forms at this point, you need to fix your tables and understand why its called a relational database.

1. You are storing redundant data. In tbl_Objects you have a a [City] field and a [CityID] field. Only one of those is needed ([CityID]). With just that number you can link to tbl_Cities to get the City text value. Don't store it in multiple places.

2. You are storing redundant data. Same as above, but for Region. No need for [Region] in tbl_Objects. With [CityID] you can link to tbl_Cities and get the Region it belongs to. [Region] should not exist in tbl_Objects.

3. You are storing the wrong data. [TypesOfObjects] in tbl_Cities should be a number. It should be the value of tbl_TypesOfObjects.TypesOfObjectsID, not the text value of it. That's how you connect tables to each other with primary and foreign keys (https://www.tutorialspoint.com/sql/sql-foreign-key.htm).

4. Reserved Words as names. [Name] is a reserved word in Access (https://support.office.com/en-us/ar...-symbols-ae9d9ada-3255-4b12-91a9-f855bdd9c5a2). Those should be avoided because it makes coding and querying more difficult later on.
 
First, to accomplish what you posted about you would use the DoCmd.OpenForm method, being sure to build a filter string to limit it to just the values you want to show when you open the form.

Second, you shouldn't be worrying about forms at this point, you need to fix your tables and understand why its called a relational database.

1. You are storing redundant data. In tbl_Objects you have a a [City] field and a [CityID] field. Only one of those is needed ([CityID]). With just that number you can link to tbl_Cities to get the City text value. Don't store it in multiple places.

2. You are storing redundant data. Same as above, but for Region. No need for [Region] in tbl_Objects. With [CityID] you can link to tbl_Cities and get the Region it belongs to. [Region] should not exist in tbl_Objects.

3. You are storing the wrong data. [TypesOfObjects] in tbl_Cities should be a number. It should be the value of tbl_TypesOfObjects.TypesOfObjectsID, not the text value of it. That's how you connect tables to each other with primary and foreign keys
4. Reserved Words as names. [Name] is a reserved word in Access . Those should be avoided because it makes coding and querying more difficult later on.


Thank you very much for the advice you gave me. I will correct the date according to your advice and if possible I will ask again
Thank you again!
 
Last post was moderated for some reason. Now approved.
Posting this to trigger email notifications
 

Users who are viewing this thread

Back
Top Bottom