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

Highlight listbox record problems using recordset/.findfirst

Scott Price
1,384 Expert 1GB
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 7730
JKing
1,206 Expert 1GB
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 Expert 1GB
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 Expert 1GB
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 Expert 1GB
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 Expert 1GB
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
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...
1
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...
17
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...
1
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...
20
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
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...
10
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...
7
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...
3
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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
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...

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.