473,468 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to require user to select value from combo box?

167 New Member
MS2007 - I have 2 combo boxes, 'cboDivisions' & 'cboGroups'. User selects the division from 'cboDivisions' but not all Divisions have groups associated. If there are no groups for the selected division, I set cboGroups invisible property. The problem I am having is my users are not always selecting a Group for a Division when there are some present. I want to force them to select a Group when the Divsion had them. I have put some code in the Form_BeforeUpdate event. The test for cbo_group.value works and the msbbox is displayed
Here is the code I am using:
Expand|Select|Wrap|Line Numbers
  1. If IsNull(cbo_group.value) or (cbo_group.value) = "" Then
  2.    msgbox "Group is required"
  3.    cbo_group.setfocus
  4.    Exit sub
  5. End If
  6. ]
I thought about putting the code on the exit of the cbo_groups event, however, if the user does not click in the group combo box, it won't work. Any suggestions?
Sep 12 '12 #1
10 6211
Seth Schrock
2,965 Recognized Expert Specialist
You could use a before update event on the form to check if cbo_group is null and cancel if it is null. You would probably have to come up with another If/Then/Else check to see if cbo_group is supposed to have a value. You might be able to check if it is visible and if it is, then run the check to see if it is null.
Sep 12 '12 #2
Rabbit
12,516 Recognized Expert Moderator MVP
Set the field as required in the table.
Sep 12 '12 #3
ncsthbell
167 New Member
Seth, I did put the code in the before update event on the form and I check to see if null. I do have an if/then/else test to see if the division has groups wrapped around the code I have above. How do I 'cancel'? Haven't used this before. I have always used 'exit sub'.
Sep 12 '12 #4
ncsthbell
167 New Member
Rabbit,
The divisions and groups are in two different tables and some groups can belong to multiple divisions so setting the field as required in the table does not work in this situation.
But thanks for the suggestion!
Sep 12 '12 #5
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Before the Exit sub, you simply do:
Expand|Select|Wrap|Line Numbers
  1. Cancel=True
Sep 12 '12 #6
ncsthbell
167 New Member
I put the cancel=True in my code before the Exit Sub so my code looks like this:
Expand|Select|Wrap|Line Numbers
  1. If vGroupRqd = True Then 
  2.   If IsNull(cbo_Group.Value)  Then
  3.      MsgBox "Group is required for this Division.", , "Select Group from drop down list"
  4.     [cbo_Group].SetFocus
  5.      cancel = True
  6.      Exit Sub
  7.   End If
  8. End If
  9.  
The problem is now that it closes the form it is on and goes back to the main form. I start with 'Main Menu' (form) and from there I select 'Edit Data' (form). This is the form that has all info for the asset that has division/group assignments. This is the form I put the code on, I want to stay on this data edit form and have the 'focus' set on the group combo box. Not sure why it is closing the form completly.
Sep 12 '12 #7
Seth Schrock
2,965 Recognized Expert Specialist
What action is triggering the form's Before_Update event? Are you trying to close the form or just going on to the next record?
Sep 12 '12 #8
ncsthbell
167 New Member
On the form, I am selecting a Division from the combo box, I assume this is what is triggering the Before_update event.
Sep 12 '12 #9
zmbd
5,501 Recognized Expert Moderator Expert
don't assume where the before_update event is being triggered from... double check as both the form and the control can have such an event.
-z
Sep 12 '12 #10
Seth Schrock
2,965 Recognized Expert Specialist
Good point z. The form's before_update event shouldn't trigger until the record is left, either by going to the next record or closing the form. Otherwise, there isn't anything in that code to close the form. You should look through your other events to see if some other event is triggering it to close.
Sep 12 '12 #11

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

Similar topics

0
by: Jim | last post by:
Hi, there, I am a beginner on Access. I have been taking so long time to try to figure out his, but so far, no clues. I want to select 2 combo boxes and Access will automatically fill in...
5
by: | last post by:
Greets I have sucessfully created a sql database and vb.net program locally connecting to my local server. (I used visual studio 2003) I would like to send the database along with the compiled...
6
by: Michi | last post by:
Hallo, of course, this doesn't work: document.getElementById('ID').style.-moz-user-select = 'text'; - but i hope it shows my problem... Is it possible to set this css option by javascript and...
2
by: vinkumar | last post by:
Hi, I have to search for string and replace with user input value using js. I have used inner HTML (objExplorer.Document.body.innerHTML) to get user input. (Eg: If user inputs web port no. as...
12
by: tadisaus2 | last post by:
Hello, Checkbox form validation - how to make a user select 4 check boxes? I have a question of a few checkboxes and how do I require a user to check 2 checkboxes (no more, no less)? Here is my...
5
by: skyy | last post by:
Hi.. I am trying to create a perl-cgi script to make a upload page such that when the user select a file using the "Browse" button, the filename will appear on another textbox. i understand...
5
neo008
by: neo008 | last post by:
Hi All, How can I select a combo box item programatically. I am using VB6 and I have populated a combo box from database. NE☼
0
by: dgs | last post by:
How to scan the user-entered value ? like, we have "scanf()" in 'C'.......
10
by: dkyadav80 | last post by:
<html> /// here what shoud be java script for: ->when script run then not display all input text field only display selection field. ->when user select other value for institute only this...
2
by: jerald m | last post by:
Hi, how can i pass the user input value of ( in text box field) to the another Jsp in url? Form Code <td> <input type="text" name="dil_ProjectCode" id="dil_ProjectCode"> </td>
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.