473,663 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Click ListBox executes the wrong code.

675 Contributor
I have 2 ListBoxes, ColumnCount=1 with lbxAlpha1.RowSo urce = "A";"C";"E" ; . . . and lbxAlpha2.RowSo urce = "B";"D";"F" ; . . . All works fine as long as I only use one of the ListBoxes. When I have used one, and click the other, I get run-time error '94', and the value for the ListBox is Null.

The error occurs at the Call NewLetter() for the WRONG ListBox (See Code Below).

I have skipped the Call statement and with 'Step Into' determined that the form/click called the _click procedure, not elsewhere in the code.

If I remove the clearing of the other box by removing the lbxAlpha1 & 2 statements, then both ListBoxes have Null values at the point of error, even though the correct letter is highlighted on the form in each ListBox.

Find for entire project for 'lbxAlpha' does not find any other occurrances except initialization in Form_Load.

Any suggestions?

Windows XP & Access 2002

Private Sub lbxAlpha1_Click ()
lbxAlpha2 = ""
Call NewLetter(lbxAl pha1)
End Sub 'lbxAlpha1_Clic k
Private Sub lbxAlpha2_Click ()
lbxAlpha1 = ""
Call NewLetter(lbxAl pha2)
End Sub 'lbxAlpha2_Clic k

From the form, I click lbxAlpha1=A, then C, then E, then F and error occurs @Call NewLetter(lbxAl pha1) in Sub lbxAlpha1_Click (), but I should be in Sub lbxAlpha2_Click ()
Mar 11 '07 #1
14 2557
MMcCarthy
14,534 Recognized Expert Moderator MVP
Is the control source of the listboxes bound to anything?

Mary
Mar 11 '07 #2
OldBirdman
675 Contributor
Is the control source of the listboxes bound to anything?

Mary
No, both are Unbound, Enabled=True, Visible=True, Locked=False, RowSourceType=V alue List
Mar 11 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub lbxAlpha1_Click()
  3.     lbxAlpha2 = ""
  4.     Call NewLetter(lbxAlpha1)
  5. End Sub 'lbxAlpha1_Click
  6. Private Sub lbxAlpha2_Click()
  7.     lbxAlpha1 = ""
  8.     Call NewLetter(lbxAlpha2)
  9. End Sub 'lbxAlpha2_Click
  10.  
Can you explain in English exactly what this event code is trying to do and post the code for the Newletter() function.
From the form, I click lbxAlpha1=A, then C, then E, then F and error occurs @Call NewLetter(lbxAl pha1) in Sub lbxAlpha1_Click (), but I should be in Sub lbxAlpha2_Click ()
I don't really understand what you mean here but answering my first question should clarify the situation.

Mary
Mar 11 '07 #4
OldBirdman
675 Contributor
Explanation in Plain English (probably too long):

A common problem is to display a record from a table with a form with DefaultView = 'Single Form' MS Access supplies Navigation Buttons (with a Record Number Box), but this is not a useful tool. I am trying to write a generic program to use as a starting point whenever this same problem occurs. As an older person, I want larger buttons and text, making it faster to use the mouse accurately, especially a touchpad on a laptop. I dislike switching from mouse to keyboard for a single task, such as find & display a record, and dislike the scrollbar with long lists.

lbxAlpha is a ListBox on the left edge of the form, containing in Value List * 9 A B C . . . Y Z (*=All & 9=starts with a number).

lbxSelect is a ListBox immediately to the right containing a list to choose from, whether an 'Address Book', a list of DVDs rented so I don't pay for something I've already seen, a list of the bird species of the world (my hobby), or any other such list, such as Employees, Products, Suppliers, Countries or States, etc.

The remainder of the form contains controls bound to a table.

Using movies rented as an example, with a table named tMovies and a form named fMain. User makes a choice in lbxAlpha, say the letter 'K' The procedure 'NewLetter' generates an SQL statement for lbxSelect. The WHERE clause would be 'WHERE (tMovies.Title LIKE "K*") ' Then lbxSelect.RowSo urce=SQL. By default, form displays the first record in the list. The essense of NewLetter is:

Sub NewLetter (strLetter as String)
Forms!fMain.lbx Select.RowSourc e = _
"SELECT tMovies.Key, tMovies.Title " & _
"FROM tMovies " & _
"WHERE (tMovies.Title LIKE """ & strLetter & "*"") " & _
"ORDER BY tMovies.Title;"
Forms!fMain.Fil ter = "Key=" & Forms!fMain.lbx Select.Column(0 ,0)
End Sub 'NewLetter

Sub NewLetter is more complex to deal with letters chosen resulting in lbxSelect being empty (ListCount=0), a "Filter Dialog" (Year>2004; Director=Eastwo od; Starring=Clint; etc), and numbers being sorted with 1 < 2 < 34 < 101, etc.

Selecting any displayed choice in lbxSelect displays the correct record by fMain.Filter="K ey=" & lbxSelect. No need to consider any filter choices by user, as all done by NewLetter and presented in lbxSelect, not by fMain.Filter. I can also add Next & Previous buttons or program the arrow keys, as these use the lbxSelect.Colum n property and fMain.Filter=.

All of the above works fine. The error occurred when I split lbxAlpha into lbxAlpha1 and lbxAlpha2, in order to get larger letters (FontSize=20). As NewLetter is passed a length=1 string containing a letter (or 9 or *), it still works. Starting the program works as long as I select entirely within either lbxAlpha1 or within lbxAlpha2. When I change from lbxAlpha1 to lbxAlpha2, the code for lbxAlpha1_click is executed. It is not called from executing lbxAlpha1 = "", as removing this statement has no effect.

I have re-booted the computer as sometimes Access gets messed up. I use Windows XP (ver 5.1, SP 2) and Access 2002.
Mar 12 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub NewLetter (strLetter as String)    
  3.    Forms!fMain.lbxSelect.RowSource = _
  4.       "SELECT tMovies.Key, tMovies.Title " & _
  5.       "FROM tMovies " & _
  6.       "WHERE (tMovies.Title LIKE """ & strLetter & "*"") " & _     
  7.       "ORDER BY tMovies.Title;"  
  8.    Forms!fMain.lbxSelect.Requery
  9.    Forms!fMain.Filter = "Key=" & Forms!fMain.lbxSelect.Column(0,0)
  10.  
  11. End Sub 'NewLetter
  12.  
Try adding a requery statement as in the above.

Mary
Mar 12 '07 #6
OldBirdman
675 Contributor
Doesn't change anything.

lbxAlpha1 will work fine as long as I don't try to use lbxAlpha2. lbxAlpha2 works until I try to use lbxAlpha1.

The code always ends up in the wrong lbxAlpha_Click subroutine, with both lbxAlpha1 and lbxAlpha2 = Null. Clicking lbxSelect produces the same error, code ends up at Call NewLetter(lbxAl pha1) if lbxAlpha1 was the ListBox I started with.

Initialization (Form_Load) calls lbxAlpha1("*"), but this doesn't stop me from clicking lbxAlpha2. So it the click, not the call to lbxAlpha1 that is the problem. I have no events in the Project that capture mouse events.

I very much appreciate your attention to this. Thank you.
Mar 12 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub lbxAlpha1_AfterUpdate()
  3.    lbxAlpha2 = ""
  4.    NewLetter(lbxAlpha1)
  5. End Sub 'lbxAlpha1_Click
  6.  
  7. Private Sub lbxAlpha2_AfterUpdate()
  8.    lbxAlpha1 = ""
  9.    NewLetter(lbxAlpha2)
  10. End Sub 'lbxAlpha2_Click
  11.  
Try putting them in the AfterUpdate instead of the Click event.

Mary
Mar 12 '07 #8
OldBirdman
675 Contributor
This results in the ListBox clicked having no value, not even Null.

When Private Sub lbxAlpha1_Click () then Immediate Window:
?lbxAlpha1
Null
?lbxAlpha2
Null

When Private Sub lbxAlpha1_After Update() then Immediate Window:
?lbxAlpha1

?lbxAlpha2
Null
Mar 12 '07 #9
MMcCarthy
14,534 Recognized Expert Moderator MVP
Can you post the row source of lbxAlpha1. Also what is the bound column number.
Mar 12 '07 #10

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

Similar topics

17
3111
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP) Me.lboxRP.SetSelected(newRPindex, True) When the last line executes, I get an error message:
7
2006
by: Colleyville Alan | last post by:
I have an app in which users are displayed a list of mutual fund from which they can choose. There is a listbox embedded in a two-tabbed notebook control. When the form is initally opened, the listbox loads info: Private Sub Form_Open(Cancel As Integer) TabControl.Value = 0 Tab_Label1.Caption = "Select Alternatives from the Select List" FundAlternativesList.RowSource = "Load_Select_Alternatives_Form" Call Highlight_Defaults End Sub
4
14529
by: Thomas | last post by:
Hello; I am creating a multiselect listbox and I would like to use checkboxes to indicate which items are selected (rather than the default highlighting.) I would then place these selected items in a table. I would also like to have the ability to "select all" and "deselect all". Any help on accomplishing the above would be greatly appreciated. Thanks;
1
2673
by: objectref | last post by:
Hi to all, i have an app that i allow a drag and drop operation of picture boxes on a panel. when i drop a picture box i do the following so my newly dropped picture box will be able to respond to these 2 events: pbox.MouseDown += new MouseEventHandler(pbox_MouseDown); pbox.DoubleClick += new EventHandler(pbox_DoubleClick);
6
30003
by: Dan Bass | last post by:
If you look at explorer, right clicking on a file, first selects the file, then throws up the context menu relating to that selection. With a Windows ListBox control and a simple context menu, the default behaviour seems to display the context menu on the listbox, but there is no selection. Now I know that explorer's using a listview, and that the context menu acts differently if you click on open space (no selection), but can I...
6
6175
by: Steve | last post by:
Hi, I open up a webform (vb.net) and populate a listbox control on the Page load event. If I click on (select) and item from the listbox I want to write the value of the selected item to a label control. Nothing happens. But when I click a button (which contains same code to write to label) I get the value of the selected item in the Label.
2
1791
by: dan NY | last post by:
I'm a struggling new VB Applications user that has what may be a simple question, but I've been struggling with it. I'm using a response to a message box YesNo question to cause one of two previously created listboxes to populate. These listboxes are each linked to ranges of cells that appear or are blanked out by IF statements in excel formulas =IF(a1=1,"company name","") - the contents of cell A1 becomes 1 based on an affirmative response...
4
4746
by: Jeff User | last post by:
Hi Using .NET 1.1, C#, web app I (actually our client) would like to be able to double click a selection in a listbox and have it postback to server . There I would want to access the item that was double clicked. Any idea how to go about this? Thanks
15
2361
by: Doogie | last post by:
I have a .net app that a user currently enters a number in a text box, hits a button and a data call is executed. She wants the ability to enter in multiple numbers (up to 100). So to make things look better visually for that, I created a listbox under the text box. She enters the number in the text box, clicks another button I added and the number is stored in the list box. Then my plan was to grab all those numbers from the list box...
0
8436
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8858
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8771
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8634
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7371
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4182
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
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
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1757
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.