473,585 Members | 2,657 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close DropDown of ComboBox2 & Open ComboBox1 on Error

7 New Member
I have several cascading ComboBoxes & would like to close Cbo2 & open Cbo1
when there is an error. These CboBoxes are on an Excel spreadsheet, not a UserForm.

I have the following code, if the Dropdown is opened it requeries Cbo2 to
ListIndex = 0. But I also want it to close (unselect, undrop list) Cbo2 &
open (select, dropdown) Cbo1 on MsgBox error. This insures the user selects
property of Cbo1 first.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cbo2_MouseDown(ByVal Button As Integer, _
  2.   ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  3.  
  4.     If Cbo1.Value = "0" Then
  5.  
  6.         MsgBox "Error, choose ComboBox1, first"
  7.         Cbo2.ListIndex = 0
  8.  
  9. 'I want to deselect the Cbo2 DropDown
  10.         Cbo2.DropDown = False  'Compile error here
  11. 'Select Cbo1, like Select.Range
  12.         Cbo1.DropDown
  13.  
  14.     Else
  15.         Cbo2.ListIndex = 0
  16.     End If
  17. End Sub
--
Thanks, Kevin
Sep 23 '09 #1
16 10574
NeoPa
32,566 Recognized Expert Moderator MVP
There seems to be no way to cancel the .Dropdown explicitly Kevin (not that I could find anyway) however, setting the focus to another control (and then back again if required) seems to do the trick for you.

Good luck & Welcome to Bytes!
Sep 23 '09 #2
OldBirdman
675 Contributor
It won't work in the MouseDown event, but in the MouseUp you can use SendKeys and send F4. Warning, the F4 will do a dropdown if it is not already dropped down, and I know of no way of determining the state of the dropdown list.
Expand|Select|Wrap|Line Numbers
  1. SendKeys "{F4}"
Sep 24 '09 #3
FishVal
2,653 Recognized Expert Specialist
The following seems to be an undocumented feature - that means you've been warned.

Any operation with MSForms.Combobo x.Locked property makes dropdown list dissapear.

e.g.
the following code does nothing, but calling "Lock" property which results in dropdown list disappearing.
Expand|Select|Wrap|Line Numbers
  1. dummy = <combobox ref>.Locked
  2.  
FYI: DropDown is a method of MSForms.Combobo x class. You cannot assign value to it (like you could do with property) and the only thing it does is showing dropdown list.

Regards,
Fish

PS. "Locked" property seems to be not the only option - actually, one from a bunch.
A trivial
Expand|Select|Wrap|Line Numbers
  1. With <combobox ref>
  2.     .Value = .Value
  3. End With
  4.  
does the same.
Sep 24 '09 #4
NeoPa
32,566 Recognized Expert Moderator MVP
@FishVal
I tried that one Fish (some experimenting to see if I could find something), and it didn't work for me. I use Access 2003.
Sep 24 '09 #5
FishVal
2,653 Recognized Expert Specialist
@afsskier
. .
Sep 24 '09 #6
AFSSkier
7 New Member
Instead of the MouseDown sub, I tried a Change sub with a Cbo.Enable = True/False to disable and enable the proceeding Active ComboBoxes. It works great for the Cascading Dropdowns.

However I’m getting a “Run-time error 1004” on the Enable = True/False, from my CmdButton sub “CmdRefreshAll_ Click” (see 2nd sub below). It has an ActiveWorkbook. RefreshAll. I even tried reversing the If in the Cbo.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Cbo1_Change()
  2.     If Cbo1.Value = "0" Then
  3.         Cbo2.ListIndex = 0
  4.         Cbo3.ListIndex = 0
  5.         Cbo4.ListIndex = 0
  6.         'Run-time error 1004 on ActiveWorkbook.RefreshAll (see CmdRefreshAll sub)
  7.         Cbo2.Enabled = False
  8.         Cbo3.Enabled = False
  9.         Cbo4.Enabled = False
  10.     Else
  11.         Cbo2.ListIndex = 0
  12.     'Run-time error 1004 on ActiveWorkbook.RefreshAll (see CmdRefreshAll sub)
  13.         Cbo2.Enabled = True
  14.  End If
  15. End Sub
  16.  
  17. Private Sub CmdRefreshAll_Click()
  18. 'Refresh data sheets from outside data sources & Pivotsheets
  19.     Application.ScreenUpdating = False
  20.     ActiveWorkbook.RefreshAll
  21. 'Add RefreshAll date & time to Form page
  22.     Sheets(1).Select
  23.     Range("H1").Value = "Refresh All Date: "
  24.     Range("H2").Value = Now
  25.     Application.ScreenUpdating = True
  26. MsgBox "All Data Sheets & Pivot Tables in this Workbook are updated"
  27. End Sub
Sep 24 '09 #7
NeoPa
32,566 Recognized Expert Moderator MVP
@FishVal
Ah. I missed that.
Sep 24 '09 #8
NeoPa
32,566 Recognized Expert Moderator MVP
Kevin,

I have edited two of your posts now that included code without the tags. I left edit comments but it appears you haven't noticed them. Please use the tags in future.

Administrator.

PS. Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your Profile Options (Look near the bottom of the page).
Sep 24 '09 #9
AFSSkier
7 New Member
Is it possible to disable sheet1 from being Refreshed by an ActiveWorkbook. RefreshAll?

It would resolve the Run-time error in the cbo.Click sub for sheet1. I don't want it to distrub the CboBoxes anyway.

I only want the ActiveWorkbook. RefreshAll to Refresh the data/Pivot sheets.
Sep 24 '09 #10

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

Similar topics

19
13038
by: Albretch | last post by:
Hi, client wants for a window with no toolbars to open (technical and 'esthetical' reasons) after the window, user clicks on, is being closed. I told them about security settings in browsers and no cross-browsers solutions and all of that we know, but they have told me they have seen that before and how then the annoying pop-up windows...
1
4141
by: alan_sec | last post by:
I' m sending query to DB2 7.2 (installed on Win 2000) using JDBC driver COM.ibm.db2.jdbc.net.DB2Driver like this: String query = "SELECT dercert from vacert " + "WHERE vrijediod=(select max(vrijediod) from vacert where vrijediod<?)"; java.sql.Timestamp timeStamp = new java.sql.Timestamp(System.currentTimeMillis());
2
3619
by: Chris Becker | last post by:
This is my attempt to rephrase a question I asked earlier that got no response. I suspect it was my poor/unplanned wording. Here is another attempt: I have a form with some drop down lists. I would like the user to be able to start filling in the form, then get to one of the dropdown lists (ex: Service Type) and realize that the dropdown...
1
1788
by: Lauchlan M | last post by:
I get the following error. Apart from the fact that it does not make any grammatical sense, what would be likely to be causing it? The background is that nxCmdDeleteErrorLogItem is a delete command with the SQL Delete from ErrorLog where LogID = ? and LogID is a parameter corresponding to a DB field LogID which is an autoinc field...
1
1395
by: Lauchlan M | last post by:
I get the following error. Apart from the fact that it does not make any grammatical sense, what would be likely to be causing it? I have a command component 'nxCmdDeleteErrorLogItem' with the following SQL: Delete from ErrorLog where LogID = ? LogID is a parameter corresponding to a DB field LogID which is an autoinc field (the...
3
5922
by: Karan | last post by:
I am calling finalize when form2 loads and deactivates form1 which closes form1. However, same thing is not happening in form2 because finalize is already called. Does anybody has solution to it. This code works well for splash screen. I searched alot on net for codes but they don't work. for example- (1) Public Sub CloseForm(formType As...
7
5808
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed to be two techniques for earlier versions. But the window.opener='' ;window.close(); and the window.open('','_parent','') ;window.close(); ...
1
9680
by: William Youngman | last post by:
I have a gridview displaying data and would like to use the AJAX dropdown extender so that when the user clicks on a record a dropdown menu will display providing the user with a menu of selections to choose from (yes much like the SharePoint 2007 dropdown menu). I'm having problems dynamically binding the 'TargetControlID' property of the...
1
2249
by: ncsthbell | last post by:
I have an Access 2000 database (running on Windows XP) that is used as a model and each user grabs a copy of this and puts onto their own drive. I have had 2 folks have issues with it lately. When they try to open it, the application does not fully open. What you see is a blank grey form with the dark blue title bar at the top with the...
0
7908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
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 we have to send another system
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.