473,386 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,386 software developers and data experts.

Help working with Option Groups, Command Buttons, and Combo Boxes

beacon
579 512MB
Hi,

I am creating a relatively simple database, but I've come across something that I haven't been able to find an answer for. I typically research until I'm blue in the face, so my frustration must be pretty high for me to actually post this.

I have a form, called frmCampusSelect, that has an option group with 2 options and has a submit and close button below it. I have written code to close this form and I have written code to submit that the user has chosen one of the 2 options, but I'm unable to take what the user has selected and have it alter the form that opens, frmEmployee, when the user selects submit.

On frmEmployee, there's a combo box that's row source queries a table I set up with one campus' programs. The problem is that there are 2 campus' and I'm trying to use the option group to determine whether the combo box is filled with the programs from the first campus or from the second campus.

The row source for the 'Programs' combo box is 'SELECT tblProgramV.ProgramV, tblProgramV.ProgramV FROM tblProgramV;

The control source is to the Programs field on the Employees table.

To reiterate, I want the user to select a campus, press submit, and have the program combo box populate with the programs that correspond to the user's selection.

I'm sure this is something easy, but I'm having the worst time with it today. Is it the weekend yet?
Sep 25 '07 #1
8 2261
Scott Price
1,384 Expert 1GB
Sorry! It's still Tuesday :-)

In the Row Source of your combo box, you'll have to point to some kind of WHERE clause that differentiates between the two campuses. I assume you have some kind of a CampusID field?

So in the code for your submit command button you'll have to capture the value returned from the option group, translate it into which CampusID it looks up, and feed that into the combo box Row Source... With me so far?

The values returned by your option group will be 1 or 2. So write an If---Then statement into your command button's on click event setting the Row Source of your combo box. You'll have to make sure the form is open, of course, before setting the row source.
In your button's on click event:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmEmployees"
  2.  
  3. If [OptionGroupName] = 1 Then
  4.   Forms!frmEmployee![ComboBoxName].RowSourceType = "Table/Query"
  5.   Forms!frmEmployee![ComboBoxName].RowSource = "SELECT ... FROM ... WHERE CampusID = ..."
  6. If [OptionGroupName = 2 Then
  7.   Etc...
  8. End If
  9.  
  10. Me.Close
Give this a try and let me know how you get along.

Regards,
Scott
Sep 25 '07 #2
beacon
579 512MB
While I was waiting for Scott's reply I was able to get the Program combo box to print out all of the items in one of the Programs, but not just the ones specified by the users input.

Here's what I have:

Two different groups of Programs identified by the Campus (V or W)

tblEmployee
text field Program (control source for Program in frmEmployee)

tblProgramV
ProgramID (auto number)
Program (text field)
Program 1
Program 2
Program 3

tblProgramW
ProgramID (auto number)
Program (text field)
Program 1
Program 2
Program 3


frmCampusSelect
optionGroup
optionV with optionLabelV
optionW with optionLabelW
cmdCancel
Expand|Select|Wrap|Line Numbers
  1. Public Sub cmdCancel_Click()
  2.                DoCmd.Close acForm, Me.Name
  3.           End Sub
cmdSubmit
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSubmit_Click()
  2.                If optionGroup.Value > 1 Then
  3.                    DoCmd.OpenForm "frmEmployee", acNormal, , , acFormAdd
  4.                    DoCmd.Close acForm, Me.Name
  5.                Else
  6.                    MsgBox "Please select a Campus!", vbExclamation + vbOKOnly
  7.                End If
  8.           End Sub
frmEmployee
combo box Program
Row Source Type = "Table/Query"
Row Source = SELECT tblProgramV.ProgramV, tblProgramV.ProgramV FROM tblProgramV;

Scott's way sounds better and seems to be what I'm looking for, but I can't get the code he gave me to work. I'm sure it has to do with my row source being incorrect, but who knows?
Sep 25 '07 #3
Scott Price
1,384 Expert 1GB
Is the code you gave for the row source copy and pasted? If so, take a closer look at what you are asking the database to do! The Select statement contains duplicate values.

Just on a quick glance it looks like you have a design/normalization issue with your tables. Have a look at this tutorial and see if you can see what I mean: Database Normalisation and Table Structures

As for making the code I gave you work, can you paste in what you tried and mention the error message it gave?

Regards,
Scott
Sep 26 '07 #4
beacon
579 512MB
Is the code you gave for the row source copy and pasted? If so, take a closer look at what you are asking the database to do! The Select statement contains duplicate values.

Just on a quick glance it looks like you have a design/normalization issue with your tables. Have a look at this tutorial and see if you can see what I mean: Database Normalisation and Table Structures

As for making the code I gave you work, can you paste in what you tried and mention the error message it gave?

Regards,
Scott
I guess I did have a normalization problem with the Program tables. I should have one Program table with either a 1 or a 2 to distinguish between the campuses. This should match up with my optionGroup where the user selects which campus they want.

I changed the row source to read "SELECT tblprogram.Program FROM tblprogram WHERE (((tblprogram.ProgramID)=[optiongroup])) ORDER BY tblprogram.Program;

Then I went to the code for cmdSubmit and typed in the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSubmit_Click()
  2.     DoCmd.OpenForm "frmEmployee", acNormal, , , acFormAdd
  3.  
  4.     If [optionGroup] = 1 Then
  5.         Forms!frmEmployee![Program].RowSourceType = "Table/Query"
  6.         Forms!frmEmployee![Program].RowSource = "SELECT tblprogram.program FROM tblprogram WHERE ProgramID = 1"
  7.     ElseIf [optionGroup] = 2 Then
  8.         Forms!frmEmployee![Program].RowSourceType = "Table/Query"
  9.         Forms!frmEmployee![Program].RowSource = "SELECT tblprogram.program FROM tblprogram WHERE ProgramID = 2"
  10. End If
  11.     DoCmd.Close acForm, Me.Name
  12. End Sub
This doesn't return any errors, but it also doesn't populate the Program combo box with any values. It's like I'm not getting my parameters passed. The same thing happened to me yesterday when I tried Scott's code.

I feel very close to the answer, but I'm still having trouble. I'm used to using C++ and being able to cout anything to the screen to test whether or not my values are correct before I pass them. Obviously, in this case, they aren't because they continue to return an empty, multiline combo box.

If anyone can help, I sure would appreciate it.
Sep 26 '07 #5
cyberdwarf
218 Expert 100+
You should be able to pass the User's selection to the opened form by using the OpenArgs argument to DoCmd.OpenForm.

This value can be picked up in the OnLoad event of the opened form, eg:-
Expand|Select|Wrap|Line Numbers
  1. Private UserChoice As Variant
  2.  
  3. Private Sub Form_Load()
  4.      UserChoice = Me.OpenArgs
  5. End Sub
The UserChoice variable may now be used to build your controlsource, or for any other purposes.

HTH

Steve
Sep 26 '07 #6
beacon
579 512MB
You should be able to pass the User's selection to the opened form by using the OpenArgs argument to DoCmd.OpenForm.

This value can be picked up in the OnLoad event of the opened form, eg:-
Expand|Select|Wrap|Line Numbers
  1. Private UserChoice As Variant
  2.  
  3. Private Sub Form_Load()
  4.      UserChoice = Me.OpenArgs
  5. End Sub
The UserChoice variable may now be used to build your controlsource, or for any other purposes.

HTH

Steve
I finally was able to get it to work. When I defined my row source, I was including my openargs in the quotes with the select statement. Small oversight on my part that ended up causing me big headaches.

Thanks everyone for you help.
Sep 26 '07 #7
Scott Price
1,384 Expert 1GB
You're welcome and glad you got it working!

Thanks for posting back with what went wrong, and what went right ;-)

Regards,
Scott
Sep 27 '07 #8
beacon
579 512MB
Sure thing...I actually stumbled upon the Locals Window and that opened up Pandora's box for me. It made me wonder how I ever got around in Visual Basic without them.

It definitely made passing my values easier. I feel dumb because I probably wouldn't have had to post this if I had known about it before.

Anyway thanks again...
Sep 27 '07 #9

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

Similar topics

6
by: Ann Duguay | last post by:
Hi there! Newbie here... :-) I'm trying to validate a form but can't seem to get it to work... Here's a copy of the code: The user has to select a color for every select box. How is this...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: mark | last post by:
I've been working on an Access 2000 database for a couple of weeks now. I took a course in access about a year ago, a crash course, and I learned a ton, but I didn't touch Access for the year since...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
5
by: deaconj999 | last post by:
Hi, I have nearly finished my database and I would like to add a query that uses a combo box to get the results, not the usual paramater style input. I suppose it would need a form and a query...
28
by: jverri01 | last post by:
First, I am relatively new to working with variables. Most of my experience has been with interface design. i am using ACCESS ver. 2003, running in Windows XP. Second, I spent an hour searching...
3
by: Strasser | last post by:
In a nested subform in datasheet view, an interviewer of homeless people picks a descriptive CATEGORY from 20 descriptive categories. The 20 categories are displayed via a combo box. (Categories...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.