473,396 Members | 1,734 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,396 software developers and data experts.

Click ListBox executes the wrong code.

675 512MB
I have 2 ListBoxes, ColumnCount=1 with lbxAlpha1.RowSource = "A";"C";"E"; . . . and lbxAlpha2.RowSource = "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(lbxAlpha1)
End Sub 'lbxAlpha1_Click
Private Sub lbxAlpha2_Click()
lbxAlpha1 = ""
Call NewLetter(lbxAlpha2)
End Sub 'lbxAlpha2_Click

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

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

Mary
No, both are Unbound, Enabled=True, Visible=True, Locked=False, RowSourceType=Value List
Mar 11 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
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(lbxAlpha1) 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 512MB
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.RowSource=SQL. By default, form displays the first record in the list. The essense of NewLetter is:

Sub NewLetter (strLetter as String)
Forms!fMain.lbxSelect.RowSource = _
"SELECT tMovies.Key, tMovies.Title " & _
"FROM tMovies " & _
"WHERE (tMovies.Title LIKE """ & strLetter & "*"") " & _
"ORDER BY tMovies.Title;"
Forms!fMain.Filter = "Key=" & Forms!fMain.lbxSelect.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=Eastwood; 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="Key=" & 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.Column 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 Expert Mod 8TB
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 512MB
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(lbxAlpha1) 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 Expert Mod 8TB
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 512MB
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_AfterUpdate() then Immediate Window:
?lbxAlpha1

?lbxAlpha2
Null
Mar 12 '07 #9
MMcCarthy
14,534 Expert Mod 8TB
Can you post the row source of lbxAlpha1. Also what is the bound column number.
Mar 12 '07 #10
OldBirdman
675 512MB
lbxAlpha1
.ColumnCount=1
.ColumnWidth=1"
.ControlSource=
.RowSourceType=Value List
.RowSource="*";"A";"C";"E";"G";"I";"K";"M";"O";"Q" ;"S";"U";"W";"Y"
.BoundColumn=1

lbxAlpha2 - Same except
.RowSource="9";"B";"D";"F";"H";"J";"L";"N";"P";"R" ;"T";"V";"X";"Z"

lbxSelect
.ColumnCount=2
.ColumnWidth=0";20"
.ControlSource=
.RowSourceType=Table/Query
.RowSource=
.BoundColumn=1
Mar 12 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. Sub NewLetter (strLetter as String)    
  2.    Forms!fMain.lbxSelect.RowSource = _
  3.       "SELECT tMovies.Key, tMovies.Title " & _
  4.       "FROM tMovies " & _
  5.       "WHERE (tMovies.Title LIKE '" & strLetter & "*" "') " & _     
  6.       "ORDER BY tMovies.Title;"  
  7.    Forms!fMain.lbxSelect.Requery
  8.    Forms!fMain.Filter = "Key=" & Forms!fMain!lbxSelect
  9.  
  10. End Sub 'NewLetter
  11.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub lbxAlpha1_AfterUpdate()
  2.    Me.lbxAlpha2 = Null
  3.    NewLetter(Me.lbxAlpha1)
  4. End Sub 'lbxAlpha1_Click
  5.  
  6. Private Sub lbxAlpha2_AfterUpdate()
  7.    Me.lbxAlpha1 = Null
  8.    NewLetter(Me.lbxAlpha2)
  9. End Sub 'lbxAlpha2_Click
  10.  
Mar 12 '07 #12
OldBirdman
675 512MB
No apparent effect with these changes. It is executing the WRONG code. I click lbxAlpha2, and the error occurs in Private Sub lbxAlpha1_AfterUpdate(). In that procedure, lbxAlpha1 is supposed to be Null. That part is OK. The underlying question is "Why does Access execute the wrong code?", which is kind of where I started.

I tried running this on another computer, Access 2000 instead of 2002, and get a message "Update or CancelUpdate without AddNew or Edit."

As I do not believe I have made any changes to a bound control, I should not get that error. As the results are not the same on both computers, either Access has a bug, or some interaction within my code is causing problems. Sometimes I feel like I spend 2/3 of the time just getting around Access problems, and 1/3 writing code. Somewhat frustrating figuring out whether it is my problem or Microsoft's.

There is something beyond these 3 ListBoxes going on here. I will need a day to work on this myself, with the entire code. The code I have presented here is, of course, stripped of all the little details.

I just now started with a new database, 4 controls lbxAlpha1, lbxAlpha2, lbxSelect, and txtTitle bound to Title, the form bound to table tMovie. I copied my original code, as presented in this forum. I added:

Private Sub lbxSelect_Click()
Forms!fMain.Filter = "Key=" & lbxSelect
End Sub 'lbxSelect_Click

It works as expected. Although I copied the original tMovies from the old program, the code will work with any table named "tMovies" with a field named "Key" and another named "Title".
Mar 12 '07 #13
OldBirdman
675 512MB
I found it!!!!

The offending statement is "Forms!fMain.lbxTitleSelect.Selected(0) = True" This is to highlight the correct Title in lbxSelect when the selection was not made with the mouse, but programically (arrow keys or clicking lbxAlpha1, etc.). "Forms!fAAA.lbxSelect = iixFormKey" where iixFormKey is the key just found in NewLetter is the correct statement.

I can see nothing wrong with the offending statement. I wanted to select the first item (default for new letter). Microsoft Visual Basic Help has:
You can use the Selected property to select items in a list box by using Visual Basic. For example, the following expression selects the fifth item in the list:
Me!Listbox.Selected(4) = True


I wish to thank you for all your effort. I feel like I got personal attention and not a cursory response. I will have more questions, asked on a new thread, but not immediately. Thank you. OldBirdman
Mar 12 '07 #14
MMcCarthy
14,534 Expert Mod 8TB
I found it!!!!

The offending statement is "Forms!fMain.lbxTitleSelect.Selected(0) = True" This is to highlight the correct Title in lbxSelect when the selection was not made with the mouse, but programically (arrow keys or clicking lbxAlpha1, etc.). "Forms!fAAA.lbxSelect = iixFormKey" where iixFormKey is the key just found in NewLetter is the correct statement.

I can see nothing wrong with the offending statement. I wanted to select the first item (default for new letter). Microsoft Visual Basic Help has:
You can use the Selected property to select items in a list box by using Visual Basic. For example, the following expression selects the fifth item in the list:
Me!Listbox.Selected(4) = True


I wish to thank you for all your effort. I feel like I got personal attention and not a cursory response. I will have more questions, asked on a new thread, but not immediately. Thank you. OldBirdman
Delighted to hear you've found your problem. As you probably already knew errors are often in the most unexpected places.

Mary
Mar 12 '07 #15

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

Similar topics

17
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)...
7
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...
4
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...
1
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...
6
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,...
6
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...
2
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...
4
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...
15
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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...
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...

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.