473,765 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Highlight listbox record problems using recordset/.findfirst

Scott Price
1,384 Recognized Expert Top Contributor
I'm not quite ready to give up on this yet... Using MS Access 2003, WinXP SP2.

I have a listbox that I'm trying to get to highlight (select) a specific record using the GotFocus event (the listbox setfocus is passed by a combobox afterupdate event).

The code I have is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub lstRate_GotFocus()
  2. Dim rs As DAO.Recordset
  3. Dim SelDate As Date
  4. 'Dim MyVarBM As Long
  5.  
  6. SelDate = DMax("[DateChange]", "tblDate")
  7.     Set rs = Me.lstRate.Recordset
  8.     With rs
  9.         .MoveLast
  10.         .FindFirst "[DateChange] = #" & SelDate & "#"
  11.         If .NoMatch Then
  12.             MsgBox "No Match Found"
  13.         End If
  14.     End With
  15. End Sub

The code executes fine, the list box recieves the focus, .nomatch is set to false, the variables populate as desired... However the desired record is not highlighted in the listbox!

Anyone able to help me here??

Thanks in advance!
Regards,
Scott
Aug 8 '07 #1
5 7754
JKing
1,206 Recognized Expert Top Contributor
Hi there, what is the record source of the list box?

I think the basic logic of what you want to do is to loop through the items in your listbox until a column value = your criteria. Once found grab the row and pass that into the Selected property and set it to true. This will "highlight" or select the record you want.

So perhaps you can give some insight as to what the criteria is being based off and what info is in your listbox.
Aug 8 '07 #2
Scott Price
1,384 Recognized Expert Top Contributor
Hi there JKing...

The record source of the listbox is this query in the Row Source:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblDate.DateID, tblDate.DateQuarter, tblDate.InvoiceNo, tblDate.QOrderID, tblDate.DateChange FROM tblDate; 
I'll try the selected property and get back to you...

Thanks!
Regards,
Scott
Aug 8 '07 #3
JKing
1,206 Recognized Expert Top Contributor
Here's a quick and dirty example of looping through the listbox and setting the selected property.

Expand|Select|Wrap|Line Numbers
  1. Dim intCount As Integer
  2. For intCount = 0 To Me.List10.ListCount - 1
  3.     If Me.List10.Column(0, intCount) = "Some Value" Then
  4.         Me.List10.Selected(intCount) = True
  5.     End If
  6. Next
  7.  
The Column property takes in a column position starting at 0 and then a row number also starting at 0. If you want to look at the first column in the first row it would be Column(0,0). Third column 10 row would look like (2,9). I'm sure you get the picture.

Any further questions let me know and good luck!
Aug 8 '07 #4
Scott Price
1,384 Recognized Expert Top Contributor
Thanks again JKing... You gave me the nudge on the right direction... This is the code I came up with that finally worked:

Expand|Select|Wrap|Line Numbers
  1. Private Sub lstDate_GotFocus()
  2. Dim rs As DAO.Recordset
  3. Dim SelDate As Date
  4. Dim MyVarBM As Long
  5.  
  6. SelDate = DMax("[DateChange]", "tblDate")
  7.     Set rs = Me.lstDate.Recordset
  8.     With rs
  9.         .MoveLast
  10.         .FindFirst "[DateChange] = #" & SelDate & "#"
  11.         MyVarBM = .AbsolutePosition 'returns the row # of the offending record
  12.         'Debug.Print MyVarBM
  13.         Me!lstDate.Selected(MyVarBM) = True 'selects the offending row
  14.         If .NoMatch Then
  15.             MsgBox "No Match Found"
  16.         End If
  17.     End With
  18. End Sub
Thanks again,
Regards,
Scott
Aug 8 '07 #5
JKing
1,206 Recognized Expert Top Contributor
Great, glad you got things working. Sometimes all you need is that little nudge.

Jared
Aug 8 '07 #6

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

Similar topics

4
4762
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record onto the bottom of the list (even though it keeps its record number). Also, There are certin names that i click on the list, and it will not bring it up, rather it brings to the first record (no matter how many times i try going to that...
1
3015
by: Skully Matjas | last post by:
Thank you for getting back to me. I am very new at this so i didnot understand what you said, here i will give as much cetails as possible: 1) The combo box i am using is combox39 2) I imported a a table of parents of a school (it has name,address,#, etc...) 3) I nead to input a ID Number (ralphs card) for some of the parents 4) The ID numbers do not go inorder of the parents, and i am not being handed the id numbers in order 4) I want...
17
4224
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset Set rs = Me.RecordsetClone rs.Find "=" & lngContractID If Not rs.EOF Then Me.Bookmark = rs.Bookmark I must site the Heisenberb Uncertainty Principal here, as it
1
6678
by: Geir Baardsen | last post by:
Hi! On frmItems I have a two listboxes. The first, lstAllCategories, is loaded with data from tblCategory when frmItems open. When user click lstAllCategories, the lstSelectedItems will show all records for that category. Now when user clicks chosen item in lstSelectedItems, textboxes in form will be filled and now user can edit the selected item.
20
10675
by: MS | last post by:
Access 97 I want to requery the data being displayed on a form, then I want to return to the record I was in. Why doesn't this code work? Private Sub CmdRefsh_Click()
8
12105
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
10
5035
by: ApexData | last post by:
Hello How do I goto a specific record in a BOUND form when the form has a primary index of ID which is autonumbered. I need to visit 4 seperate records, one at a time. This works for RecNO but no good for Field search: DoCmd.GoToRecord , , acGoTo, 19 And I know is NOT recommended.
7
2915
by: boyleyc | last post by:
Hi all I have written a database in access and used ADODB recordsets all the way through. The only recordsets that are not ADODB are the listbox navigation code automatically generated by access 2003 as follows : ' Find the record that matches the control. Dim rs As Object Set rs = Me.Recordset.Clone
3
3279
by: boliches | last post by:
I am trying to get a continuous form to highlight lines individually (ideally on hover). I have used the following code as recommended by a previous entry on this website. My problems begin in that my Database does not appear to recognise "FindFirst". The sample database I downloaded for help does recognise the script and when I begin to type the drop down gives the prompt for "FindFirst"! Why is it that my MDB does not? The only drop downprompt...
0
10163
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...
1
9957
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
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
6649
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
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...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.