Help Please

CollieDog

New member
Local time
Today, 16:25
Joined
Mar 2, 2014
Messages
3
Hi,
I am new to access and struggling with a form. I have a form called "Projects" that has a combo box to select the specific project. I need to select a particular project from the combo box and then select and open another form specific to the selected project. I have added a button to the main form and am trying to add code along the lines of if combo value = x then open form xx when button is activated.

Any code would be great if possible

Thanks in advance.
 
Do you mean you want to open;
  • (1) completely different forms depending on the project
    >If Project = XYZ open form 1
    >If Project = DGS open form 2
    >....
  • (2) a form to display details about the selected project?
    >open form 1 to show details of Project XYZ
    >Open form 1 to show details of Project DGS

(1) you would need a field in your projects table identifying the form. You would then use a Dlookup() to get the form name and use the DoCmd.OpenForm() method
(2) You would use the FK (Foreign Key) in the Details tbale that links it to the PK (primary Key) in your Projects table DoCmd.OpenForm(Name,,,"[ProjID]=" & Combobox)
 
Last edited:
Thanks Isskint,
Its option 2. I have a form with project info that has a combo box that selects a specific project and shows info regarding the selected project. I have unrelated forms with data such as previous budget allocations. I want a user to select there project via combo box, view and change details and if necessary open previous budget from a button on the main form. I have inserted a DoCmd.OpenForm but it is not linked with combo box so it does not open the correct.

Sorry if this sounds absurd!!!!
 
CollieDog, nothing sounds absurd - well there was this one time when...... sorry side tracked there :p:banghead:

Hopefully you have the following in place (apologies if this is obvious to you, but you never know the level of knowledge people have);
  • A Primary Key {PK} in the Projects table (it has the little key next to it in design view)
  • In the ProjectDetails table, a field linking it to the PK in the Projects table - known as a foreign key {FK} (No symbol, you just need that field)
  • Created a relationship between the PK and FK (some people do not do this, but it is normally important to do so)
  • The rowsource for the Project list combobox on the main form includes the PK and it is the bound column

With that in place, you could display the project details form from a button click or after the user selects the project in the combobox (the comboboxes AfterUpdate event).

The basic code would be
Code:
docmd.OpenForm("ProjDetailsFormName",acNormal,,"[ProjID]=" & me.ComboBoxProjectList)

I have included a basic example DB for you. It uses both AfterUpdate and a button.
Now if all that makes sense to you, hopefully you should have everything working fine. Anything that has you going **Like WTF:eek:** i will be happy to help further, but to make things easier, please can you attach a copy of the database (remove the data if it is sensitive) OR some screen shots of the design views of the 2 tables.

Incidentally - and not wanting to confuse the situation further - i would probably have the details form as a subform on the Projects form, but that depends on the amount of information you want to display.
 

Attachments

Last edited:
Thank you kindly Isskint for your help. To be honest I did not try :banghead: ID number but it certainly makes more sense. I am defintely still learning Access so your help is outstanding and greatly appreciated. I will give your advice a go and let you know the outcome.

Thanks once again.
 

Users who are viewing this thread

Back
Top Bottom