473,503 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Force user to select a option form Combobox

3 New Member
Hi
I'm a newby . Created a from via wizard with two combo boxes. In the first user must select a Customer. Based on first selection, second combo box displayed Material List of selected Customer again for selection. This is all working 100%

Problem : I want to force user to select a Customer in first combo box. If nothing is selected, the Access must "force" a selection.

Below is not working ?
If user does not select anything I do get the TEST message displayed, but the "Me.Mat_PSlipIN_NewCustomer.SetFocus" does not force the focus back to the first combobox for selection.

Hope I've explained myself....

Expand|Select|Wrap|Line Numbers
  1. Private Sub Mat_PSlipIN_NewCustomer_Exit(Cancel As Integer)
  2.     If IsNull(Mat_PSlipIN_NewCustomer.Value) Or Mat_PSlipIN_NewCustomer.Value = "" Then
  3.         msgbox "TEST"
  4.         Me.Mat_PSlipIN_NewCustomer.SetFocus
  5.     Else
  6.     End If
  7. End Sub

Please assist !
Sep 14 '18 #1
5 2806
twinnyfo
3,653 Recognized Expert Moderator Specialist
Johan99,

Welcome to Bytes!

Have you done a direct copy and paste from your project? Because the MsgBox function is not in “CamelCase” it appears you have not. We always recommend a direct copy and paste, so we know that what is in your project is what you have given us.

Based upon what you have given us, there is no indication as to why the focus does not stay on that particular control, other than the fact that you have exited the control. You may try using the AfterUpdate Event instead.

Along different lines, whenever I want to force a user to enter data into a specific control (as you have described), I disable all other controls until the control in question has received acceptable data. I also use that Control’s AfterUpdate event to drive the activity. Hence:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Mat_PSlipIN_NewCustomer_AfterUpdate()
  2.     Me.TheNextControl.Enabled = _
  3.         Not (IsNull(Mat_PSlipIN_NewCustomer.Value) Or _
  4.             (Mat_PSlipIN_NewCustomer.Value = ""))
  5. End Sub
There is also much more that can be done with such a set up.

On a side note, it may ease the strain on your fingers to have shorter names for your controls, along with a standardized naming convention for the type of control. For example, if Mat_PSlipIN_NewCustomer is a combo box, then, an appropriate prefix for that control and a shortened name should be sufficient, such as cboNewCustomer. This all goes to preference and clarity—not just for your sake, but for anyone else who might come after you and try to decipher your code.
Sep 14 '18 #2
Johan99
3 New Member
Hi thanks for speedy response.
1. Yes I have just copied and paste the code . Excuse my ignorance but what is Camelcase ??
2. I've used your code in the AfterUpdate routine, but still not working...
3. Agree with the naming - make good sense. I'm busy renaming all. Thx for advise

Anything else I should check ? ( I really do appreciate your valued time to assist this newby :)
Sep 14 '18 #3
twinnyfo
3,653 Recognized Expert Moderator Specialist
1. If you had truly copied and pasted your code from your VBA project, then “msgbox” (which is all lower case) would have been posted as “MsgBox” (which is CamelCase—there are upper and lower case letters).

2. You don’t say what is not working about the new code that you have tried. Have you inserted breaks at different points along the code to see if it is even going through the code?

We need a little more detail before we can help with troubleshooting.
Sep 15 '18 #4
Johan99
3 New Member
Hi

Sorry you're right - not a proper copy and paste. I concentrated so on code itself I must have changed the "Camelcase". This is way iim a newby and you are the Expert !
I took your advise regarding naming of controls.

See below revised code.
If I select a Customer from cboCustomerList I do get the TEST message as proof that code is working and then the cboMaterialList is updated with the correct material list.
If however I do not select a Customer in cboCustomerList and either press Enter or Tab, focus moves to cboMaterialList without giving me the TEST message and this resulted in the cboMaterialList that is empty (which is correct --> no customer - no material list)

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCustomerList_AfterUpdate()
  2.     Me.cboMaterialList.Enabled = _
  3.         Not (IsNull(cboCustomerList.Value) Or _
  4.             (cboCustomerList.Value = ""))
  5.             MsgBox "Test"
  6.             Me.cboMaterialList.Requery
  7. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboMaterialList_GotFocus()
  2.         cboMaterialList = ""
  3. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboMaterialList_LostFocus()
  2.     Dim nuweMaterialNo As String
  3.     Customer_ID = cboCustomerList
  4.  
  5.     If Len(cboMaterialList) < 1 Then
  6.         Cancel = True
  7.     Else
  8.         Product_ID = cboMaterialList
  9.     End If
  10. End Sub
Sep 15 '18 #5
twinnyfo
3,653 Recognized Expert Moderator Specialist
I think you essentially have the answer already. Instead of using the AfterUpdate event on cboCustomerList, use the LostFocus event. If your cboMaterialList combo box was disabled by default, then it would be impossible to move to it in the first place.

In the cboCustomerList combo box’s LostFocus event, check to see if that control has a value. If not, then do nothing (or inform the user that they need to select a value). If there is a value, then request the cboMaterialList.

I hope this makes sense. I would remove any code associated with cboMaterialList for now, unless there is an additional data check for what the user selects from it.

Like I said, I think you are very close to the final solution.
Sep 15 '18 #6

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

Similar topics

1
3417
by: Michael Hoffmann | last post by:
Hello, As you might guess I am completely new to this language. Maybe I get some help here. I try to execute a user defined funciton from a select option in a document to read a file into an...
7
8064
by: David Clark | last post by:
Hi I have two list boxes( i.e. SELECT OPTION ), one is for STATE and second is for CITY. If I change the STATE, CITY should also be updated and of course it will be having respective cities How...
19
8589
by: Neal | last post by:
I can have a visitor choose a subject line for an email. <div><label for="subject">Subject:</label><br /> <select class="form" id="subject" name="subject"> <option value="one">One</option>...
4
2581
by: Old Lady | last post by:
Hi, I need help! I have a SELECT/OPTION list. My goal is to have a TEXT input field in a form that is normally disabled, but it should become enabled when the user select one predefined OPTION....
7
2405
by: brendan.wong | last post by:
hello. i have a really simple form that asks the user to select a Month from a dropdown. the first time a user visits the page, the highlighted option should be October, which works fine. then,...
1
3198
by: billypit | last post by:
Hi, I am totaly new to MS Access. I have one form in MS Access in which i want that whenever i select an item from combobox then in the textbox on the same form or subform i want value from table...
2
5509
by: Cron | last post by:
Hi I'm trying to make a form that makes it optional for the user to save the inputted data. If the user does not tap the save button before leaving the form, the data is silently discarded. This...
1
27083
by: suadik | last post by:
Am trying to insert multiple fees into my database from a select option, but when I send, only one record is inserted which is the first selection. I also want it in such a way that when I insert,...
2
1676
by: kimmcms | last post by:
Hello everyone. I am a real newbie to php, and this is my first attempt at writing anything. I have created a Contact Form in html with a drop down selection box, which sends the completed form...
0
7093
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
7291
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
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
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...
1
5023
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
4690
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
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.