473,413 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

How to open form based on combo box selection.

I have this form called "switchboard" and in it are two combo boxes: Organization and Staff Initials (cboOrganization, cboStaff_init). There is also a search button called "OK". See picture "DB1"

What I want to do is, based on the selection of my "Staff Initials" combo box, when I click the "OK" button, I want the Multiple Items Form (Test 2) to open that correspond only to that "Staff Initials". See Picture DB2 and DB 1.

I'm really new at this VBA code, please provide code if possible.
Attached Images
File Type: jpg DB1.jpg (11.2 KB, 1236 views)
File Type: jpg DB2.jpg (14.7 KB, 969 views)
Jul 20 '10 #1

✓ answered by beacon

Hi raka,

I'm going to assume that your field in the "Test 2" form for staff initials is called Staff_Init. If it's different, you'll need to modify it in the code. The idea behind the code is that you are creating a filter for the form and triggering it when you open the form from the "switchboard" form. You'll need to make sure that the "Allow Filters" property for the "Test 2" form is set to "Yes".

In the Click event for the command button on your "switchboard" form, enter the following code:

Expand|Select|Wrap|Line Numbers
  1. Dim myVar 'This is a variable for the value in the Staff combobox
  2.  
  3. myVar = "[Staff_Init] = '" & cboStaff_Init.Value & "'" 'This is the filter...the single quotation marks indicate that the value being passed is a string. If it were a date you'd need the "#" sign and if it was a number you wouldn't need single quotations or the "#" signs.
  4.  
  5. DoCmd.OpenForm "[Test 2]", WhereCondition:=myVar 'This opens the form with the filter you created above.
  6.  
This should get you taken care of.

11 11900
AccessIdiot
493 256MB
Look into DoCmd.OpenForm and put it in the onclick event of your button.
Jul 20 '10 #2
beacon
579 512MB
Hi raka,

I'm going to assume that your field in the "Test 2" form for staff initials is called Staff_Init. If it's different, you'll need to modify it in the code. The idea behind the code is that you are creating a filter for the form and triggering it when you open the form from the "switchboard" form. You'll need to make sure that the "Allow Filters" property for the "Test 2" form is set to "Yes".

In the Click event for the command button on your "switchboard" form, enter the following code:

Expand|Select|Wrap|Line Numbers
  1. Dim myVar 'This is a variable for the value in the Staff combobox
  2.  
  3. myVar = "[Staff_Init] = '" & cboStaff_Init.Value & "'" 'This is the filter...the single quotation marks indicate that the value being passed is a string. If it were a date you'd need the "#" sign and if it was a number you wouldn't need single quotations or the "#" signs.
  4.  
  5. DoCmd.OpenForm "[Test 2]", WhereCondition:=myVar 'This opens the form with the filter you created above.
  6.  
This should get you taken care of.
Jul 20 '10 #3
When I click on the button it says that the form "TEST 2" does not exist or its misspelled. However that is the actual name of the form. Any idea what could be happening? The snaff_init values come from Table 1.

See attachment on next post.
Jul 20 '10 #4
see new attachment
Attached Images
File Type: jpg db3.jpg (14.8 KB, 749 views)
Jul 20 '10 #5
beacon
579 512MB
Try it without the brackets around "Test 2" in the code and see if that works. Usually a form, table, query, etc. that has spaces in the name has to be enclosed in brackets, but maybe that isn't the case with the DoCmd (I never have that problem because I don't put spaces in the names of my objects...just so you know, it's not good practice to create with spaces in the name, so you may want to consider that in your future developments).
Jul 20 '10 #6
Jerry Maiapu
259 100+
In post#3 try, try removing these brackets.. [] in code line 5. And try that..
Should be something like this..

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Test 2", WhereCondition:=myVar 
Cheers

Passing by

JM
Jul 21 '10 #7
Jerry Maiapu
259 100+
If that does not work I do not know about access 2007 but this works in Access 2003 so try this..

Replace my previous suggestion code with this:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Test 2",,,myVar 
Jul 21 '10 #8
Thank you, it works!
Jul 21 '10 #9
Jerry Maiapu
259 100+
Which one worked..also CHOOSE the post as BEST ANSWER

Glad it helped..

Regards
Jul 21 '10 #10
It opens the form, but the staff_init box doesnt filter to the selection of the combo box, it stays in blank.
Sep 17 '10 #11
beacon
579 512MB
Do you have a Staff_Init combo box on the form that you've opened? Are you wanting the value that you entered on the calling form to appear in a combo box on the form that was opened?

If that's the case, you will probably have to send the myVar variable in the code I provided initially as an OpenArg too. Then, in the form that is opened, you'll have to assign the OpenArg to the combo box in the FormLoad event.
Sep 20 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rosy | last post by:
Hello all. I think my request is a simple one; however, I am unable to figure it out by myself. I need a form (frmCargoEntry) to open whenever the cargo dept is chosen on another field. So when...
1
by: Benaron | last post by:
I'm a javascript newbie - so although I can follow scripts and write simple ones, I get stuck when things don't work. I'm trying to have a help section on my web-site where each question/FAQ will...
1
by: starke1120 | last post by:
Is there a way to open a form based on query type.. Example.. If a certain query result is 1 then open the form to this result.. If the query results are NULL or 0 results, then open open for...
6
by: Markus_989 | last post by:
I have a LOANS table that has a list of loan details for different borrowers. I have a main switchboard with a LOANSELECT combo box (that displays a list of borrower last names and loan numbers)....
2
by: ssoman | last post by:
I was asked if I could open one of two possible data entry forms based on what is chosen in a drop down list. For example, if Teacher A is chosen from a list, then data entry form X opens. However,...
1
by: Kevin | last post by:
The menu form has two options, one to create a new estimate, the second to open an existing estimate. Under option two is a list box containing all of the estimates. There are several different...
7
imrosie
by: imrosie | last post by:
Hellol, I'm again in need of your help with my Order processing system.. My Order form is based on (query) of Customer and Order tables (includes a subform for the product data)...has a listbox...
10
by: Beatrice | last post by:
I need to open a form selecting all data from a previous form i.e: Form 1) combo box 1 named "cboYearSelect" displayed as "Year" based on qry QryYearList ( only one field "Year") ...
9
by: Patrick A | last post by:
All, I've got a continuous form with one field on it, with a comob
2
by: ghetto_banjo | last post by:
Ok, i thought i had this one figured out, apparently not. Here is my code on my button click event: stDocName = "frmInvoice" stLinkCriteria = "=" & Me! DoCmd.OpenForm stDocName, , ,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.